2012-09-17 18:38:38 +02:00
|
|
|
/* dwarf.c -- Get file/line information from DWARF for backtraces.
|
2022-01-03 10:42:10 +01:00
|
|
|
Copyright (C) 2012-2022 Free Software Foundation, Inc.
|
2012-09-17 18:38:38 +02:00
|
|
|
Written by Ian Lance Taylor, Google.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
(1) Redistributions of source code must retain the above copyright
|
2016-09-11 15:44:07 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
(2) Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the
|
2016-09-11 15:44:07 +02:00
|
|
|
distribution.
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
(3) The name of the author may not be used to
|
|
|
|
endorse or promote products derived from this software without
|
|
|
|
specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE. */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "dwarf2.h"
|
|
|
|
#include "filenames.h"
|
|
|
|
|
|
|
|
#include "backtrace.h"
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-09-18 18:50:29 +02:00
|
|
|
#if !defined(HAVE_DECL_STRNLEN) || !HAVE_DECL_STRNLEN
|
2012-10-04 17:16:09 +02:00
|
|
|
|
|
|
|
/* If strnlen is not declared, provide our own version. */
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
xstrnlen (const char *s, size_t maxlen)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < maxlen; ++i)
|
|
|
|
if (s[i] == '\0')
|
|
|
|
break;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define strnlen xstrnlen
|
|
|
|
|
2012-09-18 18:06:53 +02:00
|
|
|
#endif
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* A buffer to read DWARF info. */
|
|
|
|
|
|
|
|
struct dwarf_buf
|
|
|
|
{
|
|
|
|
/* Buffer name for error messages. */
|
|
|
|
const char *name;
|
|
|
|
/* Start of the buffer. */
|
|
|
|
const unsigned char *start;
|
|
|
|
/* Next byte to read. */
|
|
|
|
const unsigned char *buf;
|
|
|
|
/* The number of bytes remaining. */
|
|
|
|
size_t left;
|
|
|
|
/* Whether the data is big-endian. */
|
|
|
|
int is_bigendian;
|
|
|
|
/* Error callback routine. */
|
|
|
|
backtrace_error_callback error_callback;
|
|
|
|
/* Data for error_callback. */
|
|
|
|
void *data;
|
|
|
|
/* Non-zero if we've reported an underflow error. */
|
|
|
|
int reported_underflow;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A single attribute in a DWARF abbreviation. */
|
|
|
|
|
|
|
|
struct attr
|
|
|
|
{
|
|
|
|
/* The attribute name. */
|
|
|
|
enum dwarf_attribute name;
|
|
|
|
/* The attribute form. */
|
|
|
|
enum dwarf_form form;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* The attribute value, for DW_FORM_implicit_const. */
|
|
|
|
int64_t val;
|
2012-09-17 18:38:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A single DWARF abbreviation. */
|
|
|
|
|
|
|
|
struct abbrev
|
|
|
|
{
|
|
|
|
/* The abbrev code--the number used to refer to the abbrev. */
|
|
|
|
uint64_t code;
|
|
|
|
/* The entry tag. */
|
|
|
|
enum dwarf_tag tag;
|
|
|
|
/* Non-zero if this abbrev has child entries. */
|
|
|
|
int has_children;
|
|
|
|
/* The number of attributes. */
|
|
|
|
size_t num_attrs;
|
|
|
|
/* The attributes. */
|
|
|
|
struct attr *attrs;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The DWARF abbreviations for a compilation unit. This structure
|
|
|
|
only exists while reading the compilation unit. Most DWARF readers
|
|
|
|
seem to a hash table to map abbrev ID's to abbrev entries.
|
|
|
|
However, we primarily care about GCC, and GCC simply issues ID's in
|
|
|
|
numerical order starting at 1. So we simply keep a sorted vector,
|
|
|
|
and try to just look up the code. */
|
|
|
|
|
|
|
|
struct abbrevs
|
|
|
|
{
|
|
|
|
/* The number of abbrevs in the vector. */
|
|
|
|
size_t num_abbrevs;
|
|
|
|
/* The abbrevs, sorted by the code field. */
|
|
|
|
struct abbrev *abbrevs;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The different kinds of attribute values. */
|
|
|
|
|
|
|
|
enum attr_val_encoding
|
|
|
|
{
|
2019-01-17 01:07:53 +01:00
|
|
|
/* No attribute value. */
|
|
|
|
ATTR_VAL_NONE,
|
2012-09-17 18:38:38 +02:00
|
|
|
/* An address. */
|
|
|
|
ATTR_VAL_ADDRESS,
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* An index into the .debug_addr section, whose value is relative to
|
|
|
|
* the DW_AT_addr_base attribute of the compilation unit. */
|
|
|
|
ATTR_VAL_ADDRESS_INDEX,
|
2012-09-17 18:38:38 +02:00
|
|
|
/* A unsigned integer. */
|
|
|
|
ATTR_VAL_UINT,
|
|
|
|
/* A sigd integer. */
|
|
|
|
ATTR_VAL_SINT,
|
|
|
|
/* A string. */
|
|
|
|
ATTR_VAL_STRING,
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* An index into the .debug_str_offsets section. */
|
|
|
|
ATTR_VAL_STRING_INDEX,
|
2012-09-17 18:38:38 +02:00
|
|
|
/* An offset to other data in the containing unit. */
|
|
|
|
ATTR_VAL_REF_UNIT,
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* An offset to other data within the .debug_info section. */
|
2012-09-17 18:38:38 +02:00
|
|
|
ATTR_VAL_REF_INFO,
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* An offset to other data within the alt .debug_info section. */
|
2019-01-17 14:42:20 +01:00
|
|
|
ATTR_VAL_REF_ALT_INFO,
|
2012-09-17 18:38:38 +02:00
|
|
|
/* An offset to data in some other section. */
|
|
|
|
ATTR_VAL_REF_SECTION,
|
|
|
|
/* A type signature. */
|
|
|
|
ATTR_VAL_REF_TYPE,
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* An index into the .debug_rnglists section. */
|
|
|
|
ATTR_VAL_RNGLISTS_INDEX,
|
2012-09-17 18:38:38 +02:00
|
|
|
/* A block of data (not represented). */
|
|
|
|
ATTR_VAL_BLOCK,
|
|
|
|
/* An expression (not represented). */
|
|
|
|
ATTR_VAL_EXPR,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* An attribute value. */
|
|
|
|
|
|
|
|
struct attr_val
|
|
|
|
{
|
|
|
|
/* How the value is stored in the field u. */
|
|
|
|
enum attr_val_encoding encoding;
|
|
|
|
union
|
|
|
|
{
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* ATTR_VAL_ADDRESS*, ATTR_VAL_UINT, ATTR_VAL_REF*. */
|
2012-09-17 18:38:38 +02:00
|
|
|
uint64_t uint;
|
|
|
|
/* ATTR_VAL_SINT. */
|
|
|
|
int64_t sint;
|
|
|
|
/* ATTR_VAL_STRING. */
|
|
|
|
const char *string;
|
|
|
|
/* ATTR_VAL_BLOCK not stored. */
|
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The line number program header. */
|
|
|
|
|
|
|
|
struct line_header
|
|
|
|
{
|
|
|
|
/* The version of the line number information. */
|
|
|
|
int version;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* Address size. */
|
|
|
|
int addrsize;
|
2012-09-17 18:38:38 +02:00
|
|
|
/* The minimum instruction length. */
|
|
|
|
unsigned int min_insn_len;
|
|
|
|
/* The maximum number of ops per instruction. */
|
|
|
|
unsigned int max_ops_per_insn;
|
|
|
|
/* The line base for special opcodes. */
|
|
|
|
int line_base;
|
|
|
|
/* The line range for special opcodes. */
|
|
|
|
unsigned int line_range;
|
|
|
|
/* The opcode base--the first special opcode. */
|
|
|
|
unsigned int opcode_base;
|
|
|
|
/* Opcode lengths, indexed by opcode - 1. */
|
|
|
|
const unsigned char *opcode_lengths;
|
|
|
|
/* The number of directory entries. */
|
|
|
|
size_t dirs_count;
|
|
|
|
/* The directory entries. */
|
|
|
|
const char **dirs;
|
|
|
|
/* The number of filenames. */
|
|
|
|
size_t filenames_count;
|
|
|
|
/* The filenames. */
|
|
|
|
const char **filenames;
|
|
|
|
};
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* A format description from a line header. */
|
|
|
|
|
|
|
|
struct line_header_format
|
|
|
|
{
|
|
|
|
int lnct; /* LNCT code. */
|
|
|
|
enum dwarf_form form; /* Form of entry data. */
|
|
|
|
};
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Map a single PC value to a file/line. We will keep a vector of
|
|
|
|
these sorted by PC value. Each file/line will be correct from the
|
|
|
|
PC up to the PC of the next entry if there is one. We allocate one
|
|
|
|
extra entry at the end so that we can use bsearch. */
|
|
|
|
|
|
|
|
struct line
|
|
|
|
{
|
|
|
|
/* PC. */
|
|
|
|
uintptr_t pc;
|
|
|
|
/* File name. Many entries in the array are expected to point to
|
|
|
|
the same file name. */
|
|
|
|
const char *filename;
|
|
|
|
/* Line number. */
|
|
|
|
int lineno;
|
2015-06-12 02:01:50 +02:00
|
|
|
/* Index of the object in the original array read from the DWARF
|
|
|
|
section, before it has been sorted. The index makes it possible
|
|
|
|
to use Quicksort and maintain stability. */
|
|
|
|
int idx;
|
2012-09-17 18:38:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A growable vector of line number information. This is used while
|
|
|
|
reading the line numbers. */
|
|
|
|
|
|
|
|
struct line_vector
|
|
|
|
{
|
|
|
|
/* Memory. This is an array of struct line. */
|
|
|
|
struct backtrace_vector vec;
|
|
|
|
/* Number of valid mappings. */
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A function described in the debug info. */
|
|
|
|
|
|
|
|
struct function
|
|
|
|
{
|
|
|
|
/* The name of the function. */
|
|
|
|
const char *name;
|
|
|
|
/* If this is an inlined function, the filename of the call
|
|
|
|
site. */
|
|
|
|
const char *caller_filename;
|
|
|
|
/* If this is an inlined function, the line number of the call
|
|
|
|
site. */
|
|
|
|
int caller_lineno;
|
|
|
|
/* Map PC ranges to inlined functions. */
|
|
|
|
struct function_addrs *function_addrs;
|
|
|
|
size_t function_addrs_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* An address range for a function. This maps a PC value to a
|
|
|
|
specific function. */
|
|
|
|
|
|
|
|
struct function_addrs
|
|
|
|
{
|
|
|
|
/* Range is LOW <= PC < HIGH. */
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t high;
|
|
|
|
/* Function for this address range. */
|
|
|
|
struct function *function;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A growable vector of function address ranges. */
|
|
|
|
|
|
|
|
struct function_vector
|
|
|
|
{
|
|
|
|
/* Memory. This is an array of struct function_addrs. */
|
|
|
|
struct backtrace_vector vec;
|
|
|
|
/* Number of address ranges present. */
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A DWARF compilation unit. This only holds the information we need
|
|
|
|
to map a PC to a file and line. */
|
|
|
|
|
|
|
|
struct unit
|
|
|
|
{
|
|
|
|
/* The first entry for this compilation unit. */
|
|
|
|
const unsigned char *unit_data;
|
|
|
|
/* The length of the data for this compilation unit. */
|
|
|
|
size_t unit_data_len;
|
|
|
|
/* The offset of UNIT_DATA from the start of the information for
|
|
|
|
this compilation unit. */
|
|
|
|
size_t unit_data_offset;
|
2019-01-17 14:42:09 +01:00
|
|
|
/* Offset of the start of the compilation unit from the start of the
|
|
|
|
.debug_info section. */
|
2019-01-23 11:22:43 +01:00
|
|
|
size_t low_offset;
|
2019-01-17 14:42:09 +01:00
|
|
|
/* Offset of the end of the compilation unit from the start of the
|
|
|
|
.debug_info section. */
|
2019-01-23 11:22:43 +01:00
|
|
|
size_t high_offset;
|
2012-09-17 18:38:38 +02:00
|
|
|
/* DWARF version. */
|
|
|
|
int version;
|
|
|
|
/* Whether unit is DWARF64. */
|
|
|
|
int is_dwarf64;
|
|
|
|
/* Address size. */
|
|
|
|
int addrsize;
|
|
|
|
/* Offset into line number information. */
|
|
|
|
off_t lineoff;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* Offset of compilation unit in .debug_str_offsets. */
|
|
|
|
uint64_t str_offsets_base;
|
|
|
|
/* Offset of compilation unit in .debug_addr. */
|
|
|
|
uint64_t addr_base;
|
|
|
|
/* Offset of compilation unit in .debug_rnglists. */
|
|
|
|
uint64_t rnglists_base;
|
2013-01-17 02:20:28 +01:00
|
|
|
/* Primary source file. */
|
|
|
|
const char *filename;
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Compilation command working directory. */
|
|
|
|
const char *comp_dir;
|
2013-01-17 02:20:28 +01:00
|
|
|
/* Absolute file name, only set if needed. */
|
|
|
|
const char *abs_filename;
|
2012-09-17 18:38:38 +02:00
|
|
|
/* The abbreviations for this unit. */
|
|
|
|
struct abbrevs abbrevs;
|
|
|
|
|
|
|
|
/* The fields above this point are read in during initialization and
|
|
|
|
may be accessed freely. The fields below this point are read in
|
|
|
|
as needed, and therefore require care, as different threads may
|
|
|
|
try to initialize them simultaneously. */
|
|
|
|
|
|
|
|
/* PC to line number mapping. This is NULL if the values have not
|
|
|
|
been read. This is (struct line *) -1 if there was an error
|
|
|
|
reading the values. */
|
|
|
|
struct line *lines;
|
|
|
|
/* Number of entries in lines. */
|
|
|
|
size_t lines_count;
|
|
|
|
/* PC ranges to function. */
|
|
|
|
struct function_addrs *function_addrs;
|
|
|
|
size_t function_addrs_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* An address range for a compilation unit. This maps a PC value to a
|
|
|
|
specific compilation unit. Note that we invert the representation
|
|
|
|
in DWARF: instead of listing the units and attaching a list of
|
|
|
|
ranges, we list the ranges and have each one point to the unit.
|
|
|
|
This lets us do a binary search to find the unit. */
|
|
|
|
|
|
|
|
struct unit_addrs
|
|
|
|
{
|
|
|
|
/* Range is LOW <= PC < HIGH. */
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t high;
|
|
|
|
/* Compilation unit for this address range. */
|
|
|
|
struct unit *u;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A growable vector of compilation unit address ranges. */
|
|
|
|
|
|
|
|
struct unit_addrs_vector
|
|
|
|
{
|
|
|
|
/* Memory. This is an array of struct unit_addrs. */
|
|
|
|
struct backtrace_vector vec;
|
|
|
|
/* Number of address ranges present. */
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
2019-01-17 14:42:09 +01:00
|
|
|
/* A growable vector of compilation unit pointer. */
|
|
|
|
|
|
|
|
struct unit_vector
|
|
|
|
{
|
|
|
|
struct backtrace_vector vec;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* The information we need to map a PC to a file and line. */
|
|
|
|
|
|
|
|
struct dwarf_data
|
|
|
|
{
|
2012-10-09 20:20:45 +02:00
|
|
|
/* The data for the next file we know about. */
|
|
|
|
struct dwarf_data *next;
|
2019-01-17 01:07:43 +01:00
|
|
|
/* The data for .gnu_debugaltlink. */
|
|
|
|
struct dwarf_data *altlink;
|
2012-10-09 20:20:45 +02:00
|
|
|
/* The base address for this file. */
|
|
|
|
uintptr_t base_address;
|
2012-09-17 18:38:38 +02:00
|
|
|
/* A sorted list of address ranges. */
|
|
|
|
struct unit_addrs *addrs;
|
|
|
|
/* Number of address ranges in list. */
|
|
|
|
size_t addrs_count;
|
2019-01-17 14:42:09 +01:00
|
|
|
/* A sorted list of units. */
|
|
|
|
struct unit **units;
|
|
|
|
/* Number of units in the list. */
|
|
|
|
size_t units_count;
|
2019-12-05 03:20:11 +01:00
|
|
|
/* The unparsed DWARF debug data. */
|
|
|
|
struct dwarf_sections dwarf_sections;
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Whether the data is big-endian or not. */
|
|
|
|
int is_bigendian;
|
|
|
|
/* A vector used for function addresses. We keep this here so that
|
|
|
|
we can grow the vector as we read more functions. */
|
|
|
|
struct function_vector fvec;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Report an error for a DWARF buffer. */
|
|
|
|
|
|
|
|
static void
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (struct dwarf_buf *buf, const char *msg, int errnum)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
char b[200];
|
|
|
|
|
|
|
|
snprintf (b, sizeof b, "%s in %s at %d",
|
|
|
|
msg, buf->name, (int) (buf->buf - buf->start));
|
2021-03-02 22:45:56 +01:00
|
|
|
buf->error_callback (buf->data, b, errnum);
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Require at least COUNT bytes in BUF. Return 1 if all is well, 0 on
|
|
|
|
error. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
require (struct dwarf_buf *buf, size_t count)
|
|
|
|
{
|
|
|
|
if (buf->left >= count)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (!buf->reported_underflow)
|
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "DWARF underflow", 0);
|
2012-09-17 18:38:38 +02:00
|
|
|
buf->reported_underflow = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Advance COUNT bytes in BUF. Return 1 if all is well, 0 on
|
|
|
|
error. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
advance (struct dwarf_buf *buf, size_t count)
|
|
|
|
{
|
|
|
|
if (!require (buf, count))
|
|
|
|
return 0;
|
|
|
|
buf->buf += count;
|
|
|
|
buf->left -= count;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-11-21 09:31:04 +01:00
|
|
|
/* Read one zero-terminated string from BUF and advance past the string. */
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
read_string (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
const char *p = (const char *)buf->buf;
|
|
|
|
size_t len = strnlen (p, buf->left);
|
|
|
|
|
|
|
|
/* - If len == left, we ran out of buffer before finding the zero terminator.
|
|
|
|
Generate an error by advancing len + 1.
|
|
|
|
- If len < left, advance by len + 1 to skip past the zero terminator. */
|
|
|
|
size_t count = len + 1;
|
|
|
|
|
|
|
|
if (!advance (buf, count))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Read one byte from BUF and advance 1 byte. */
|
|
|
|
|
|
|
|
static unsigned char
|
|
|
|
read_byte (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
const unsigned char *p = buf->buf;
|
|
|
|
|
|
|
|
if (!advance (buf, 1))
|
|
|
|
return 0;
|
|
|
|
return p[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a signed char from BUF and advance 1 byte. */
|
|
|
|
|
|
|
|
static signed char
|
|
|
|
read_sbyte (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
const unsigned char *p = buf->buf;
|
|
|
|
|
|
|
|
if (!advance (buf, 1))
|
|
|
|
return 0;
|
|
|
|
return (*p ^ 0x80) - 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a uint16 from BUF and advance 2 bytes. */
|
|
|
|
|
|
|
|
static uint16_t
|
|
|
|
read_uint16 (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
const unsigned char *p = buf->buf;
|
|
|
|
|
|
|
|
if (!advance (buf, 2))
|
|
|
|
return 0;
|
|
|
|
if (buf->is_bigendian)
|
|
|
|
return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
|
|
|
|
else
|
|
|
|
return ((uint16_t) p[1] << 8) | (uint16_t) p[0];
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* Read a 24 bit value from BUF and advance 3 bytes. */
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
read_uint24 (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
const unsigned char *p = buf->buf;
|
|
|
|
|
|
|
|
if (!advance (buf, 3))
|
|
|
|
return 0;
|
|
|
|
if (buf->is_bigendian)
|
|
|
|
return (((uint32_t) p[0] << 16) | ((uint32_t) p[1] << 8)
|
|
|
|
| (uint32_t) p[2]);
|
|
|
|
else
|
|
|
|
return (((uint32_t) p[2] << 16) | ((uint32_t) p[1] << 8)
|
|
|
|
| (uint32_t) p[0]);
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Read a uint32 from BUF and advance 4 bytes. */
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
read_uint32 (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
const unsigned char *p = buf->buf;
|
|
|
|
|
|
|
|
if (!advance (buf, 4))
|
|
|
|
return 0;
|
|
|
|
if (buf->is_bigendian)
|
|
|
|
return (((uint32_t) p[0] << 24) | ((uint32_t) p[1] << 16)
|
|
|
|
| ((uint32_t) p[2] << 8) | (uint32_t) p[3]);
|
|
|
|
else
|
|
|
|
return (((uint32_t) p[3] << 24) | ((uint32_t) p[2] << 16)
|
|
|
|
| ((uint32_t) p[1] << 8) | (uint32_t) p[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a uint64 from BUF and advance 8 bytes. */
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
read_uint64 (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
const unsigned char *p = buf->buf;
|
|
|
|
|
|
|
|
if (!advance (buf, 8))
|
|
|
|
return 0;
|
|
|
|
if (buf->is_bigendian)
|
|
|
|
return (((uint64_t) p[0] << 56) | ((uint64_t) p[1] << 48)
|
|
|
|
| ((uint64_t) p[2] << 40) | ((uint64_t) p[3] << 32)
|
|
|
|
| ((uint64_t) p[4] << 24) | ((uint64_t) p[5] << 16)
|
|
|
|
| ((uint64_t) p[6] << 8) | (uint64_t) p[7]);
|
|
|
|
else
|
|
|
|
return (((uint64_t) p[7] << 56) | ((uint64_t) p[6] << 48)
|
|
|
|
| ((uint64_t) p[5] << 40) | ((uint64_t) p[4] << 32)
|
|
|
|
| ((uint64_t) p[3] << 24) | ((uint64_t) p[2] << 16)
|
|
|
|
| ((uint64_t) p[1] << 8) | (uint64_t) p[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read an offset from BUF and advance the appropriate number of
|
|
|
|
bytes. */
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
read_offset (struct dwarf_buf *buf, int is_dwarf64)
|
|
|
|
{
|
|
|
|
if (is_dwarf64)
|
|
|
|
return read_uint64 (buf);
|
|
|
|
else
|
|
|
|
return read_uint32 (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read an address from BUF and advance the appropriate number of
|
|
|
|
bytes. */
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
read_address (struct dwarf_buf *buf, int addrsize)
|
|
|
|
{
|
|
|
|
switch (addrsize)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return read_byte (buf);
|
|
|
|
case 2:
|
|
|
|
return read_uint16 (buf);
|
|
|
|
case 4:
|
|
|
|
return read_uint32 (buf);
|
|
|
|
case 8:
|
|
|
|
return read_uint64 (buf);
|
|
|
|
default:
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "unrecognized address size", 0);
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return whether a value is the highest possible address, given the
|
|
|
|
address size. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_highest_address (uint64_t address, int addrsize)
|
|
|
|
{
|
|
|
|
switch (addrsize)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return address == (unsigned char) -1;
|
|
|
|
case 2:
|
|
|
|
return address == (uint16_t) -1;
|
|
|
|
case 4:
|
|
|
|
return address == (uint32_t) -1;
|
|
|
|
case 8:
|
|
|
|
return address == (uint64_t) -1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read an unsigned LEB128 number. */
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
read_uleb128 (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
uint64_t ret;
|
|
|
|
unsigned int shift;
|
2012-10-04 00:07:12 +02:00
|
|
|
int overflow;
|
2012-09-17 18:38:38 +02:00
|
|
|
unsigned char b;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
shift = 0;
|
2012-10-04 00:07:12 +02:00
|
|
|
overflow = 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
const unsigned char *p;
|
|
|
|
|
|
|
|
p = buf->buf;
|
|
|
|
if (!advance (buf, 1))
|
|
|
|
return 0;
|
|
|
|
b = *p;
|
2012-10-04 00:07:12 +02:00
|
|
|
if (shift < 64)
|
|
|
|
ret |= ((uint64_t) (b & 0x7f)) << shift;
|
|
|
|
else if (!overflow)
|
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "LEB128 overflows uint64_t", 0);
|
2012-10-04 00:07:12 +02:00
|
|
|
overflow = 1;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
shift += 7;
|
|
|
|
}
|
|
|
|
while ((b & 0x80) != 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a signed LEB128 number. */
|
|
|
|
|
|
|
|
static int64_t
|
|
|
|
read_sleb128 (struct dwarf_buf *buf)
|
|
|
|
{
|
|
|
|
uint64_t val;
|
|
|
|
unsigned int shift;
|
2012-10-04 00:07:12 +02:00
|
|
|
int overflow;
|
2012-09-17 18:38:38 +02:00
|
|
|
unsigned char b;
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
shift = 0;
|
2012-10-04 00:07:12 +02:00
|
|
|
overflow = 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
const unsigned char *p;
|
|
|
|
|
|
|
|
p = buf->buf;
|
|
|
|
if (!advance (buf, 1))
|
|
|
|
return 0;
|
|
|
|
b = *p;
|
2012-10-04 00:07:12 +02:00
|
|
|
if (shift < 64)
|
|
|
|
val |= ((uint64_t) (b & 0x7f)) << shift;
|
|
|
|
else if (!overflow)
|
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "signed LEB128 overflows uint64_t", 0);
|
2012-10-04 00:07:12 +02:00
|
|
|
overflow = 1;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
shift += 7;
|
|
|
|
}
|
|
|
|
while ((b & 0x80) != 0);
|
|
|
|
|
2012-10-04 00:07:12 +02:00
|
|
|
if ((b & 0x40) != 0 && shift < 64)
|
2012-09-17 18:38:38 +02:00
|
|
|
val |= ((uint64_t) -1) << shift;
|
|
|
|
|
|
|
|
return (int64_t) val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the length of an LEB128 number. */
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
leb128_len (const unsigned char *p)
|
|
|
|
{
|
|
|
|
size_t ret;
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
while ((*p & 0x80) != 0)
|
|
|
|
{
|
|
|
|
++p;
|
|
|
|
++ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-22 01:06:27 +01:00
|
|
|
/* Read initial_length from BUF and advance the appropriate number of bytes. */
|
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
read_initial_length (struct dwarf_buf *buf, int *is_dwarf64)
|
|
|
|
{
|
|
|
|
uint64_t len;
|
|
|
|
|
|
|
|
len = read_uint32 (buf);
|
|
|
|
if (len == 0xffffffff)
|
|
|
|
{
|
|
|
|
len = read_uint64 (buf);
|
|
|
|
*is_dwarf64 = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*is_dwarf64 = 0;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Free an abbreviations structure. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_abbrevs (struct backtrace_state *state, struct abbrevs *abbrevs,
|
|
|
|
backtrace_error_callback error_callback, void *data)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < abbrevs->num_abbrevs; ++i)
|
|
|
|
backtrace_free (state, abbrevs->abbrevs[i].attrs,
|
|
|
|
abbrevs->abbrevs[i].num_attrs * sizeof (struct attr),
|
|
|
|
error_callback, data);
|
|
|
|
backtrace_free (state, abbrevs->abbrevs,
|
|
|
|
abbrevs->num_abbrevs * sizeof (struct abbrev),
|
|
|
|
error_callback, data);
|
|
|
|
abbrevs->num_abbrevs = 0;
|
|
|
|
abbrevs->abbrevs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read an attribute value. Returns 1 on success, 0 on failure. If
|
|
|
|
the value can be represented as a uint64_t, sets *VAL and sets
|
|
|
|
*IS_VALID to 1. We don't try to store the value of other attribute
|
|
|
|
forms, because we don't care about them. */
|
|
|
|
|
|
|
|
static int
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
read_attribute (enum dwarf_form form, uint64_t implicit_val,
|
|
|
|
struct dwarf_buf *buf, int is_dwarf64, int version,
|
|
|
|
int addrsize, const struct dwarf_sections *dwarf_sections,
|
2019-01-17 01:07:53 +01:00
|
|
|
struct dwarf_data *altlink, struct attr_val *val)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2012-11-20 18:28:05 +01:00
|
|
|
/* Avoid warnings about val.u.FIELD may be used uninitialized if
|
|
|
|
this function is inlined. The warnings aren't valid but can
|
|
|
|
occur because the different fields are set and used
|
|
|
|
conditionally. */
|
|
|
|
memset (val, 0, sizeof *val);
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
switch (form)
|
|
|
|
{
|
|
|
|
case DW_FORM_addr:
|
|
|
|
val->encoding = ATTR_VAL_ADDRESS;
|
|
|
|
val->u.uint = read_address (buf, addrsize);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_block2:
|
|
|
|
val->encoding = ATTR_VAL_BLOCK;
|
|
|
|
return advance (buf, read_uint16 (buf));
|
|
|
|
case DW_FORM_block4:
|
|
|
|
val->encoding = ATTR_VAL_BLOCK;
|
|
|
|
return advance (buf, read_uint32 (buf));
|
|
|
|
case DW_FORM_data2:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = read_uint16 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_data4:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = read_uint32 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_data8:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = read_uint64 (buf);
|
|
|
|
return 1;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
case DW_FORM_data16:
|
|
|
|
val->encoding = ATTR_VAL_BLOCK;
|
|
|
|
return advance (buf, 16);
|
2012-09-17 18:38:38 +02:00
|
|
|
case DW_FORM_string:
|
|
|
|
val->encoding = ATTR_VAL_STRING;
|
2018-11-21 09:31:04 +01:00
|
|
|
val->u.string = read_string (buf);
|
|
|
|
return val->u.string == NULL ? 0 : 1;
|
2012-09-17 18:38:38 +02:00
|
|
|
case DW_FORM_block:
|
|
|
|
val->encoding = ATTR_VAL_BLOCK;
|
|
|
|
return advance (buf, read_uleb128 (buf));
|
|
|
|
case DW_FORM_block1:
|
|
|
|
val->encoding = ATTR_VAL_BLOCK;
|
|
|
|
return advance (buf, read_byte (buf));
|
|
|
|
case DW_FORM_data1:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = read_byte (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_flag:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = read_byte (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_sdata:
|
|
|
|
val->encoding = ATTR_VAL_SINT;
|
|
|
|
val->u.sint = read_sleb128 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_strp:
|
|
|
|
{
|
|
|
|
uint64_t offset;
|
|
|
|
|
|
|
|
offset = read_offset (buf, is_dwarf64);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (offset >= dwarf_sections->size[DEBUG_STR])
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "DW_FORM_strp out of range", 0);
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
val->encoding = ATTR_VAL_STRING;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
val->u.string =
|
|
|
|
(const char *) dwarf_sections->data[DEBUG_STR] + offset;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case DW_FORM_line_strp:
|
|
|
|
{
|
|
|
|
uint64_t offset;
|
|
|
|
|
|
|
|
offset = read_offset (buf, is_dwarf64);
|
|
|
|
if (offset >= dwarf_sections->size[DEBUG_LINE_STR])
|
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "DW_FORM_line_strp out of range", 0);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
val->encoding = ATTR_VAL_STRING;
|
|
|
|
val->u.string =
|
|
|
|
(const char *) dwarf_sections->data[DEBUG_LINE_STR] + offset;
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case DW_FORM_udata:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = read_uleb128 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref_addr:
|
|
|
|
val->encoding = ATTR_VAL_REF_INFO;
|
|
|
|
if (version == 2)
|
|
|
|
val->u.uint = read_address (buf, addrsize);
|
|
|
|
else
|
|
|
|
val->u.uint = read_offset (buf, is_dwarf64);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref1:
|
|
|
|
val->encoding = ATTR_VAL_REF_UNIT;
|
|
|
|
val->u.uint = read_byte (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref2:
|
|
|
|
val->encoding = ATTR_VAL_REF_UNIT;
|
|
|
|
val->u.uint = read_uint16 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref4:
|
|
|
|
val->encoding = ATTR_VAL_REF_UNIT;
|
|
|
|
val->u.uint = read_uint32 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref8:
|
|
|
|
val->encoding = ATTR_VAL_REF_UNIT;
|
|
|
|
val->u.uint = read_uint64 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref_udata:
|
|
|
|
val->encoding = ATTR_VAL_REF_UNIT;
|
|
|
|
val->u.uint = read_uleb128 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_indirect:
|
|
|
|
{
|
|
|
|
uint64_t form;
|
|
|
|
|
|
|
|
form = read_uleb128 (buf);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (form == DW_FORM_implicit_const)
|
|
|
|
{
|
|
|
|
dwarf_buf_error (buf,
|
2021-03-02 22:45:56 +01:00
|
|
|
"DW_FORM_indirect to DW_FORM_implicit_const",
|
|
|
|
0);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return read_attribute ((enum dwarf_form) form, 0, buf, is_dwarf64,
|
|
|
|
version, addrsize, dwarf_sections, altlink,
|
|
|
|
val);
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
case DW_FORM_sec_offset:
|
|
|
|
val->encoding = ATTR_VAL_REF_SECTION;
|
|
|
|
val->u.uint = read_offset (buf, is_dwarf64);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_exprloc:
|
|
|
|
val->encoding = ATTR_VAL_EXPR;
|
|
|
|
return advance (buf, read_uleb128 (buf));
|
|
|
|
case DW_FORM_flag_present:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = 1;
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref_sig8:
|
|
|
|
val->encoding = ATTR_VAL_REF_TYPE;
|
|
|
|
val->u.uint = read_uint64 (buf);
|
|
|
|
return 1;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
case DW_FORM_strx: case DW_FORM_strx1: case DW_FORM_strx2:
|
|
|
|
case DW_FORM_strx3: case DW_FORM_strx4:
|
|
|
|
{
|
|
|
|
uint64_t offset;
|
|
|
|
|
|
|
|
switch (form)
|
|
|
|
{
|
|
|
|
case DW_FORM_strx:
|
|
|
|
offset = read_uleb128 (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_strx1:
|
|
|
|
offset = read_byte (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_strx2:
|
|
|
|
offset = read_uint16 (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_strx3:
|
|
|
|
offset = read_uint24 (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_strx4:
|
|
|
|
offset = read_uint32 (buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* This case can't happen. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
val->encoding = ATTR_VAL_STRING_INDEX;
|
|
|
|
val->u.uint = offset;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case DW_FORM_addrx: case DW_FORM_addrx1: case DW_FORM_addrx2:
|
|
|
|
case DW_FORM_addrx3: case DW_FORM_addrx4:
|
|
|
|
{
|
|
|
|
uint64_t offset;
|
|
|
|
|
|
|
|
switch (form)
|
|
|
|
{
|
|
|
|
case DW_FORM_addrx:
|
|
|
|
offset = read_uleb128 (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_addrx1:
|
|
|
|
offset = read_byte (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_addrx2:
|
|
|
|
offset = read_uint16 (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_addrx3:
|
|
|
|
offset = read_uint24 (buf);
|
|
|
|
break;
|
|
|
|
case DW_FORM_addrx4:
|
|
|
|
offset = read_uint32 (buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* This case can't happen. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
val->encoding = ATTR_VAL_ADDRESS_INDEX;
|
|
|
|
val->u.uint = offset;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case DW_FORM_ref_sup4:
|
|
|
|
val->encoding = ATTR_VAL_REF_SECTION;
|
|
|
|
val->u.uint = read_uint32 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_ref_sup8:
|
|
|
|
val->encoding = ATTR_VAL_REF_SECTION;
|
|
|
|
val->u.uint = read_uint64 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_implicit_const:
|
|
|
|
val->encoding = ATTR_VAL_UINT;
|
|
|
|
val->u.uint = implicit_val;
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_loclistx:
|
|
|
|
/* We don't distinguish this from DW_FORM_sec_offset. It
|
|
|
|
* shouldn't matter since we don't care about loclists. */
|
|
|
|
val->encoding = ATTR_VAL_REF_SECTION;
|
|
|
|
val->u.uint = read_uleb128 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_rnglistx:
|
|
|
|
val->encoding = ATTR_VAL_RNGLISTS_INDEX;
|
|
|
|
val->u.uint = read_uleb128 (buf);
|
|
|
|
return 1;
|
2012-09-17 18:38:38 +02:00
|
|
|
case DW_FORM_GNU_addr_index:
|
|
|
|
val->encoding = ATTR_VAL_REF_SECTION;
|
|
|
|
val->u.uint = read_uleb128 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_GNU_str_index:
|
|
|
|
val->encoding = ATTR_VAL_REF_SECTION;
|
|
|
|
val->u.uint = read_uleb128 (buf);
|
|
|
|
return 1;
|
|
|
|
case DW_FORM_GNU_ref_alt:
|
|
|
|
val->u.uint = read_offset (buf, is_dwarf64);
|
2019-01-17 01:07:53 +01:00
|
|
|
if (altlink == NULL)
|
|
|
|
{
|
|
|
|
val->encoding = ATTR_VAL_NONE;
|
|
|
|
return 1;
|
|
|
|
}
|
2019-01-17 14:42:20 +01:00
|
|
|
val->encoding = ATTR_VAL_REF_ALT_INFO;
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
case DW_FORM_strp_sup: case DW_FORM_GNU_strp_alt:
|
2019-01-17 01:08:05 +01:00
|
|
|
{
|
|
|
|
uint64_t offset;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
|
2019-01-17 01:08:05 +01:00
|
|
|
offset = read_offset (buf, is_dwarf64);
|
|
|
|
if (altlink == NULL)
|
|
|
|
{
|
|
|
|
val->encoding = ATTR_VAL_NONE;
|
|
|
|
return 1;
|
|
|
|
}
|
2019-12-05 03:20:11 +01:00
|
|
|
if (offset >= altlink->dwarf_sections.size[DEBUG_STR])
|
2019-01-17 01:08:05 +01:00
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "DW_FORM_strp_sup out of range", 0);
|
2019-01-17 01:08:05 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
val->encoding = ATTR_VAL_STRING;
|
2019-12-05 03:20:11 +01:00
|
|
|
val->u.string =
|
|
|
|
(const char *) altlink->dwarf_sections.data[DEBUG_STR] + offset;
|
2019-01-17 01:08:05 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
default:
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (buf, "unrecognized DWARF form", -1);
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* If we can determine the value of a string attribute, set *STRING to
|
|
|
|
point to the string. Return 1 on success, 0 on error. If we don't
|
|
|
|
know the value, we consider that a success, and we don't change
|
|
|
|
*STRING. An error is only reported for some sort of out of range
|
|
|
|
offset. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
resolve_string (const struct dwarf_sections *dwarf_sections, int is_dwarf64,
|
|
|
|
int is_bigendian, uint64_t str_offsets_base,
|
|
|
|
const struct attr_val *val,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
const char **string)
|
|
|
|
{
|
|
|
|
switch (val->encoding)
|
|
|
|
{
|
|
|
|
case ATTR_VAL_STRING:
|
|
|
|
*string = val->u.string;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case ATTR_VAL_STRING_INDEX:
|
|
|
|
{
|
|
|
|
uint64_t offset;
|
|
|
|
struct dwarf_buf offset_buf;
|
|
|
|
|
|
|
|
offset = val->u.uint * (is_dwarf64 ? 8 : 4) + str_offsets_base;
|
|
|
|
if (offset + (is_dwarf64 ? 8 : 4)
|
2020-12-02 20:06:40 +01:00
|
|
|
> dwarf_sections->size[DEBUG_STR_OFFSETS])
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
{
|
|
|
|
error_callback (data, "DW_FORM_strx value out of range", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset_buf.name = ".debug_str_offsets";
|
|
|
|
offset_buf.start = dwarf_sections->data[DEBUG_STR_OFFSETS];
|
|
|
|
offset_buf.buf = dwarf_sections->data[DEBUG_STR_OFFSETS] + offset;
|
|
|
|
offset_buf.left = dwarf_sections->size[DEBUG_STR_OFFSETS] - offset;
|
|
|
|
offset_buf.is_bigendian = is_bigendian;
|
|
|
|
offset_buf.error_callback = error_callback;
|
|
|
|
offset_buf.data = data;
|
|
|
|
offset_buf.reported_underflow = 0;
|
|
|
|
|
|
|
|
offset = read_offset (&offset_buf, is_dwarf64);
|
|
|
|
if (offset >= dwarf_sections->size[DEBUG_STR])
|
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (&offset_buf,
|
|
|
|
"DW_FORM_strx offset out of range",
|
|
|
|
0);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*string = (const char *) dwarf_sections->data[DEBUG_STR] + offset;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set *ADDRESS to the real address for a ATTR_VAL_ADDRESS_INDEX.
|
|
|
|
Return 1 on success, 0 on error. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
resolve_addr_index (const struct dwarf_sections *dwarf_sections,
|
|
|
|
uint64_t addr_base, int addrsize, int is_bigendian,
|
|
|
|
uint64_t addr_index,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
uint64_t *address)
|
|
|
|
{
|
|
|
|
uint64_t offset;
|
|
|
|
struct dwarf_buf addr_buf;
|
|
|
|
|
|
|
|
offset = addr_index * addrsize + addr_base;
|
2020-12-02 20:06:40 +01:00
|
|
|
if (offset + addrsize > dwarf_sections->size[DEBUG_ADDR])
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
{
|
|
|
|
error_callback (data, "DW_FORM_addrx value out of range", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr_buf.name = ".debug_addr";
|
|
|
|
addr_buf.start = dwarf_sections->data[DEBUG_ADDR];
|
|
|
|
addr_buf.buf = dwarf_sections->data[DEBUG_ADDR] + offset;
|
|
|
|
addr_buf.left = dwarf_sections->size[DEBUG_ADDR] - offset;
|
|
|
|
addr_buf.is_bigendian = is_bigendian;
|
|
|
|
addr_buf.error_callback = error_callback;
|
|
|
|
addr_buf.data = data;
|
|
|
|
addr_buf.reported_underflow = 0;
|
|
|
|
|
|
|
|
*address = read_address (&addr_buf, addrsize);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-01-17 14:42:09 +01:00
|
|
|
/* Compare a unit offset against a unit for bsearch. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
units_search (const void *vkey, const void *ventry)
|
|
|
|
{
|
2019-01-23 11:22:43 +01:00
|
|
|
const size_t *key = (const size_t *) vkey;
|
2019-01-17 14:42:09 +01:00
|
|
|
const struct unit *entry = *((const struct unit *const *) ventry);
|
2019-01-23 11:22:43 +01:00
|
|
|
size_t offset;
|
2019-01-17 14:42:09 +01:00
|
|
|
|
|
|
|
offset = *key;
|
|
|
|
if (offset < entry->low_offset)
|
|
|
|
return -1;
|
|
|
|
else if (offset >= entry->high_offset)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a unit in PU containing OFFSET. */
|
|
|
|
|
|
|
|
static struct unit *
|
2019-01-23 11:22:43 +01:00
|
|
|
find_unit (struct unit **pu, size_t units_count, size_t offset)
|
2019-01-17 14:42:09 +01:00
|
|
|
{
|
|
|
|
struct unit **u;
|
|
|
|
u = bsearch (&offset, pu, units_count, sizeof (struct unit *), units_search);
|
|
|
|
return u == NULL ? NULL : *u;
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Compare function_addrs for qsort. When ranges are nested, make the
|
|
|
|
smallest one sort last. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
function_addrs_compare (const void *v1, const void *v2)
|
|
|
|
{
|
|
|
|
const struct function_addrs *a1 = (const struct function_addrs *) v1;
|
|
|
|
const struct function_addrs *a2 = (const struct function_addrs *) v2;
|
|
|
|
|
|
|
|
if (a1->low < a2->low)
|
|
|
|
return -1;
|
|
|
|
if (a1->low > a2->low)
|
|
|
|
return 1;
|
|
|
|
if (a1->high < a2->high)
|
|
|
|
return 1;
|
|
|
|
if (a1->high > a2->high)
|
|
|
|
return -1;
|
|
|
|
return strcmp (a1->function->name, a2->function->name);
|
|
|
|
}
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Compare a PC against a function_addrs for bsearch. We always
|
|
|
|
allocate an entra entry at the end of the vector, so that this
|
|
|
|
routine can safely look at the next entry. Note that if there are
|
|
|
|
multiple ranges containing PC, which one will be returned is
|
|
|
|
unpredictable. We compensate for that in dwarf_fileline. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
function_addrs_search (const void *vkey, const void *ventry)
|
|
|
|
{
|
|
|
|
const uintptr_t *key = (const uintptr_t *) vkey;
|
|
|
|
const struct function_addrs *entry = (const struct function_addrs *) ventry;
|
|
|
|
uintptr_t pc;
|
|
|
|
|
|
|
|
pc = *key;
|
|
|
|
if (pc < entry->low)
|
|
|
|
return -1;
|
2020-09-09 03:18:48 +02:00
|
|
|
else if (pc > (entry + 1)->low)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
/* Add a new compilation unit address range to a vector. This is
|
|
|
|
called via add_ranges. Returns 1 on success, 0 on failure. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
2019-12-10 04:41:49 +01:00
|
|
|
add_unit_addr (struct backtrace_state *state, void *rdata,
|
|
|
|
uint64_t lowpc, uint64_t highpc,
|
2012-09-17 18:38:38 +02:00
|
|
|
backtrace_error_callback error_callback, void *data,
|
2019-12-10 04:41:49 +01:00
|
|
|
void *pvec)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
struct unit *u = (struct unit *) rdata;
|
|
|
|
struct unit_addrs_vector *vec = (struct unit_addrs_vector *) pvec;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct unit_addrs *p;
|
|
|
|
|
|
|
|
/* Try to merge with the last entry. */
|
|
|
|
if (vec->count > 0)
|
|
|
|
{
|
|
|
|
p = (struct unit_addrs *) vec->vec.base + (vec->count - 1);
|
2019-12-10 04:41:49 +01:00
|
|
|
if ((lowpc == p->high || lowpc == p->high + 1)
|
|
|
|
&& u == p->u)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
if (highpc > p->high)
|
|
|
|
p->high = highpc;
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = ((struct unit_addrs *)
|
|
|
|
backtrace_vector_grow (state, sizeof (struct unit_addrs),
|
|
|
|
error_callback, data, &vec->vec));
|
|
|
|
if (p == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
p->low = lowpc;
|
|
|
|
p->high = highpc;
|
|
|
|
p->u = u;
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
++vec->count;
|
2019-12-10 04:41:49 +01:00
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compare unit_addrs for qsort. When ranges are nested, make the
|
|
|
|
smallest one sort last. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
unit_addrs_compare (const void *v1, const void *v2)
|
|
|
|
{
|
|
|
|
const struct unit_addrs *a1 = (const struct unit_addrs *) v1;
|
|
|
|
const struct unit_addrs *a2 = (const struct unit_addrs *) v2;
|
|
|
|
|
|
|
|
if (a1->low < a2->low)
|
|
|
|
return -1;
|
|
|
|
if (a1->low > a2->low)
|
|
|
|
return 1;
|
|
|
|
if (a1->high < a2->high)
|
|
|
|
return 1;
|
|
|
|
if (a1->high > a2->high)
|
|
|
|
return -1;
|
|
|
|
if (a1->u->lineoff < a2->u->lineoff)
|
|
|
|
return -1;
|
|
|
|
if (a1->u->lineoff > a2->u->lineoff)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Compare a PC against a unit_addrs for bsearch. We always allocate
|
|
|
|
an entry entry at the end of the vector, so that this routine can
|
|
|
|
safely look at the next entry. Note that if there are multiple
|
|
|
|
ranges containing PC, which one will be returned is unpredictable.
|
|
|
|
We compensate for that in dwarf_fileline. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
unit_addrs_search (const void *vkey, const void *ventry)
|
|
|
|
{
|
|
|
|
const uintptr_t *key = (const uintptr_t *) vkey;
|
|
|
|
const struct unit_addrs *entry = (const struct unit_addrs *) ventry;
|
|
|
|
uintptr_t pc;
|
|
|
|
|
|
|
|
pc = *key;
|
|
|
|
if (pc < entry->low)
|
|
|
|
return -1;
|
2020-09-09 03:18:48 +02:00
|
|
|
else if (pc > (entry + 1)->low)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-12 02:01:50 +02:00
|
|
|
/* Sort the line vector by PC. We want a stable sort here to maintain
|
|
|
|
the order of lines for the same PC values. Since the sequence is
|
|
|
|
being sorted in place, their addresses cannot be relied on to
|
|
|
|
maintain stability. That is the purpose of the index member. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
line_compare (const void *v1, const void *v2)
|
|
|
|
{
|
|
|
|
const struct line *ln1 = (const struct line *) v1;
|
|
|
|
const struct line *ln2 = (const struct line *) v2;
|
|
|
|
|
|
|
|
if (ln1->pc < ln2->pc)
|
|
|
|
return -1;
|
|
|
|
else if (ln1->pc > ln2->pc)
|
|
|
|
return 1;
|
2015-06-12 02:01:50 +02:00
|
|
|
else if (ln1->idx < ln2->idx)
|
2012-09-17 18:38:38 +02:00
|
|
|
return -1;
|
2015-06-12 02:01:50 +02:00
|
|
|
else if (ln1->idx > ln2->idx)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a PC in a line vector. We always allocate an extra entry at
|
|
|
|
the end of the lines vector, so that this routine can safely look
|
|
|
|
at the next entry. Note that when there are multiple mappings for
|
|
|
|
the same PC value, this will return the last one. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
line_search (const void *vkey, const void *ventry)
|
|
|
|
{
|
|
|
|
const uintptr_t *key = (const uintptr_t *) vkey;
|
|
|
|
const struct line *entry = (const struct line *) ventry;
|
|
|
|
uintptr_t pc;
|
|
|
|
|
|
|
|
pc = *key;
|
|
|
|
if (pc < entry->pc)
|
|
|
|
return -1;
|
|
|
|
else if (pc >= (entry + 1)->pc)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the abbrevs by the abbrev code. This function is passed to
|
|
|
|
both qsort and bsearch. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
abbrev_compare (const void *v1, const void *v2)
|
|
|
|
{
|
|
|
|
const struct abbrev *a1 = (const struct abbrev *) v1;
|
|
|
|
const struct abbrev *a2 = (const struct abbrev *) v2;
|
|
|
|
|
|
|
|
if (a1->code < a2->code)
|
|
|
|
return -1;
|
|
|
|
else if (a1->code > a2->code)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This really shouldn't happen. It means there are two
|
|
|
|
different abbrevs with the same code, and that means we don't
|
|
|
|
know which one lookup_abbrev should return. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the abbreviation table for a compilation unit. Returns 1 on
|
|
|
|
success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_abbrevs (struct backtrace_state *state, uint64_t abbrev_offset,
|
|
|
|
const unsigned char *dwarf_abbrev, size_t dwarf_abbrev_size,
|
|
|
|
int is_bigendian, backtrace_error_callback error_callback,
|
|
|
|
void *data, struct abbrevs *abbrevs)
|
|
|
|
{
|
|
|
|
struct dwarf_buf abbrev_buf;
|
|
|
|
struct dwarf_buf count_buf;
|
|
|
|
size_t num_abbrevs;
|
|
|
|
|
|
|
|
abbrevs->num_abbrevs = 0;
|
|
|
|
abbrevs->abbrevs = NULL;
|
|
|
|
|
|
|
|
if (abbrev_offset >= dwarf_abbrev_size)
|
|
|
|
{
|
|
|
|
error_callback (data, "abbrev offset out of range", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
abbrev_buf.name = ".debug_abbrev";
|
|
|
|
abbrev_buf.start = dwarf_abbrev;
|
|
|
|
abbrev_buf.buf = dwarf_abbrev + abbrev_offset;
|
|
|
|
abbrev_buf.left = dwarf_abbrev_size - abbrev_offset;
|
|
|
|
abbrev_buf.is_bigendian = is_bigendian;
|
|
|
|
abbrev_buf.error_callback = error_callback;
|
|
|
|
abbrev_buf.data = data;
|
|
|
|
abbrev_buf.reported_underflow = 0;
|
|
|
|
|
|
|
|
/* Count the number of abbrevs in this list. */
|
|
|
|
|
|
|
|
count_buf = abbrev_buf;
|
|
|
|
num_abbrevs = 0;
|
|
|
|
while (read_uleb128 (&count_buf) != 0)
|
|
|
|
{
|
|
|
|
if (count_buf.reported_underflow)
|
|
|
|
return 0;
|
|
|
|
++num_abbrevs;
|
|
|
|
// Skip tag.
|
|
|
|
read_uleb128 (&count_buf);
|
|
|
|
// Skip has_children.
|
|
|
|
read_byte (&count_buf);
|
|
|
|
// Skip attributes.
|
|
|
|
while (read_uleb128 (&count_buf) != 0)
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
{
|
|
|
|
uint64_t form;
|
|
|
|
|
|
|
|
form = read_uleb128 (&count_buf);
|
|
|
|
if ((enum dwarf_form) form == DW_FORM_implicit_const)
|
|
|
|
read_sleb128 (&count_buf);
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
// Skip form of last attribute.
|
|
|
|
read_uleb128 (&count_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count_buf.reported_underflow)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (num_abbrevs == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
abbrevs->abbrevs = ((struct abbrev *)
|
|
|
|
backtrace_alloc (state,
|
|
|
|
num_abbrevs * sizeof (struct abbrev),
|
|
|
|
error_callback, data));
|
|
|
|
if (abbrevs->abbrevs == NULL)
|
|
|
|
return 0;
|
2018-11-28 15:06:23 +01:00
|
|
|
abbrevs->num_abbrevs = num_abbrevs;
|
2012-09-17 18:38:38 +02:00
|
|
|
memset (abbrevs->abbrevs, 0, num_abbrevs * sizeof (struct abbrev));
|
|
|
|
|
|
|
|
num_abbrevs = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
uint64_t code;
|
|
|
|
struct abbrev a;
|
|
|
|
size_t num_attrs;
|
|
|
|
struct attr *attrs;
|
|
|
|
|
|
|
|
if (abbrev_buf.reported_underflow)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
code = read_uleb128 (&abbrev_buf);
|
|
|
|
if (code == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
a.code = code;
|
|
|
|
a.tag = (enum dwarf_tag) read_uleb128 (&abbrev_buf);
|
|
|
|
a.has_children = read_byte (&abbrev_buf);
|
|
|
|
|
|
|
|
count_buf = abbrev_buf;
|
|
|
|
num_attrs = 0;
|
|
|
|
while (read_uleb128 (&count_buf) != 0)
|
|
|
|
{
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
uint64_t form;
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
++num_attrs;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
form = read_uleb128 (&count_buf);
|
|
|
|
if ((enum dwarf_form) form == DW_FORM_implicit_const)
|
|
|
|
read_sleb128 (&count_buf);
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num_attrs == 0)
|
|
|
|
{
|
|
|
|
attrs = NULL;
|
|
|
|
read_uleb128 (&abbrev_buf);
|
|
|
|
read_uleb128 (&abbrev_buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attrs = ((struct attr *)
|
|
|
|
backtrace_alloc (state, num_attrs * sizeof *attrs,
|
|
|
|
error_callback, data));
|
|
|
|
if (attrs == NULL)
|
|
|
|
goto fail;
|
|
|
|
num_attrs = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
uint64_t name;
|
|
|
|
uint64_t form;
|
|
|
|
|
|
|
|
name = read_uleb128 (&abbrev_buf);
|
|
|
|
form = read_uleb128 (&abbrev_buf);
|
|
|
|
if (name == 0)
|
|
|
|
break;
|
|
|
|
attrs[num_attrs].name = (enum dwarf_attribute) name;
|
|
|
|
attrs[num_attrs].form = (enum dwarf_form) form;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if ((enum dwarf_form) form == DW_FORM_implicit_const)
|
|
|
|
attrs[num_attrs].val = read_sleb128 (&abbrev_buf);
|
|
|
|
else
|
|
|
|
attrs[num_attrs].val = 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
++num_attrs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
a.num_attrs = num_attrs;
|
|
|
|
a.attrs = attrs;
|
|
|
|
|
|
|
|
abbrevs->abbrevs[num_abbrevs] = a;
|
|
|
|
++num_abbrevs;
|
|
|
|
}
|
|
|
|
|
2014-03-07 06:07:56 +01:00
|
|
|
backtrace_qsort (abbrevs->abbrevs, abbrevs->num_abbrevs,
|
|
|
|
sizeof (struct abbrev), abbrev_compare);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free_abbrevs (state, abbrevs, error_callback, data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the abbrev information for an abbrev code. */
|
|
|
|
|
|
|
|
static const struct abbrev *
|
|
|
|
lookup_abbrev (struct abbrevs *abbrevs, uint64_t code,
|
|
|
|
backtrace_error_callback error_callback, void *data)
|
|
|
|
{
|
|
|
|
struct abbrev key;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
/* With GCC, where abbrevs are simply numbered in order, we should
|
|
|
|
be able to just look up the entry. */
|
|
|
|
if (code - 1 < abbrevs->num_abbrevs
|
|
|
|
&& abbrevs->abbrevs[code - 1].code == code)
|
|
|
|
return &abbrevs->abbrevs[code - 1];
|
|
|
|
|
|
|
|
/* Otherwise we have to search. */
|
|
|
|
memset (&key, 0, sizeof key);
|
|
|
|
key.code = code;
|
|
|
|
p = bsearch (&key, abbrevs->abbrevs, abbrevs->num_abbrevs,
|
|
|
|
sizeof (struct abbrev), abbrev_compare);
|
|
|
|
if (p == NULL)
|
|
|
|
{
|
|
|
|
error_callback (data, "invalid abbreviation code", 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (const struct abbrev *) p;
|
|
|
|
}
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
/* This struct is used to gather address range information while
|
|
|
|
reading attributes. We use this while building a mapping from
|
|
|
|
address ranges to compilation units and then again while mapping
|
|
|
|
from address ranges to function entries. Normally either
|
|
|
|
lowpc/highpc is set or ranges is set. */
|
|
|
|
|
|
|
|
struct pcrange {
|
|
|
|
uint64_t lowpc; /* The low PC value. */
|
|
|
|
int have_lowpc; /* Whether a low PC value was found. */
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
int lowpc_is_addr_index; /* Whether lowpc is in .debug_addr. */
|
2019-12-10 04:41:49 +01:00
|
|
|
uint64_t highpc; /* The high PC value. */
|
|
|
|
int have_highpc; /* Whether a high PC value was found. */
|
|
|
|
int highpc_is_relative; /* Whether highpc is relative to lowpc. */
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
int highpc_is_addr_index; /* Whether highpc is in .debug_addr. */
|
2019-12-10 04:41:49 +01:00
|
|
|
uint64_t ranges; /* Offset in ranges section. */
|
|
|
|
int have_ranges; /* Whether ranges is valid. */
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
int ranges_is_index; /* Whether ranges is DW_FORM_rnglistx. */
|
2019-12-10 04:41:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Update PCRANGE from an attribute value. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_pcrange (const struct attr* attr, const struct attr_val* val,
|
|
|
|
struct pcrange *pcrange)
|
|
|
|
{
|
|
|
|
switch (attr->name)
|
|
|
|
{
|
|
|
|
case DW_AT_low_pc:
|
|
|
|
if (val->encoding == ATTR_VAL_ADDRESS)
|
|
|
|
{
|
|
|
|
pcrange->lowpc = val->u.uint;
|
|
|
|
pcrange->have_lowpc = 1;
|
|
|
|
}
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
else if (val->encoding == ATTR_VAL_ADDRESS_INDEX)
|
|
|
|
{
|
|
|
|
pcrange->lowpc = val->u.uint;
|
|
|
|
pcrange->have_lowpc = 1;
|
|
|
|
pcrange->lowpc_is_addr_index = 1;
|
|
|
|
}
|
2019-12-10 04:41:49 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_high_pc:
|
|
|
|
if (val->encoding == ATTR_VAL_ADDRESS)
|
|
|
|
{
|
|
|
|
pcrange->highpc = val->u.uint;
|
|
|
|
pcrange->have_highpc = 1;
|
|
|
|
}
|
|
|
|
else if (val->encoding == ATTR_VAL_UINT)
|
|
|
|
{
|
|
|
|
pcrange->highpc = val->u.uint;
|
|
|
|
pcrange->have_highpc = 1;
|
|
|
|
pcrange->highpc_is_relative = 1;
|
|
|
|
}
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
else if (val->encoding == ATTR_VAL_ADDRESS_INDEX)
|
|
|
|
{
|
|
|
|
pcrange->highpc = val->u.uint;
|
|
|
|
pcrange->have_highpc = 1;
|
|
|
|
pcrange->highpc_is_addr_index = 1;
|
|
|
|
}
|
2019-12-10 04:41:49 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_ranges:
|
|
|
|
if (val->encoding == ATTR_VAL_UINT
|
|
|
|
|| val->encoding == ATTR_VAL_REF_SECTION)
|
|
|
|
{
|
|
|
|
pcrange->ranges = val->u.uint;
|
|
|
|
pcrange->have_ranges = 1;
|
|
|
|
}
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
else if (val->encoding == ATTR_VAL_RNGLISTS_INDEX)
|
|
|
|
{
|
|
|
|
pcrange->ranges = val->u.uint;
|
|
|
|
pcrange->have_ranges = 1;
|
|
|
|
pcrange->ranges_is_index = 1;
|
|
|
|
}
|
2019-12-10 04:41:49 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* Call ADD_RANGE for a low/high PC pair. Returns 1 on success, 0 on
|
|
|
|
error. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
add_low_high_range (struct backtrace_state *state,
|
|
|
|
const struct dwarf_sections *dwarf_sections,
|
|
|
|
uintptr_t base_address, int is_bigendian,
|
|
|
|
struct unit *u, const struct pcrange *pcrange,
|
|
|
|
int (*add_range) (struct backtrace_state *state,
|
|
|
|
void *rdata, uint64_t lowpc,
|
|
|
|
uint64_t highpc,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data, void *vec),
|
|
|
|
void *rdata,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
void *vec)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
uint64_t lowpc;
|
|
|
|
uint64_t highpc;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
lowpc = pcrange->lowpc;
|
|
|
|
if (pcrange->lowpc_is_addr_index)
|
2019-12-10 04:41:49 +01:00
|
|
|
{
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!resolve_addr_index (dwarf_sections, u->addr_base, u->addrsize,
|
|
|
|
is_bigendian, lowpc, error_callback, data,
|
|
|
|
&lowpc))
|
|
|
|
return 0;
|
2019-12-10 04:41:49 +01:00
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
highpc = pcrange->highpc;
|
|
|
|
if (pcrange->highpc_is_addr_index)
|
2019-12-10 04:41:49 +01:00
|
|
|
{
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!resolve_addr_index (dwarf_sections, u->addr_base, u->addrsize,
|
|
|
|
is_bigendian, highpc, error_callback, data,
|
|
|
|
&highpc))
|
|
|
|
return 0;
|
2019-12-10 04:41:49 +01:00
|
|
|
}
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (pcrange->highpc_is_relative)
|
|
|
|
highpc += lowpc;
|
|
|
|
|
|
|
|
/* Add in the base address of the module when recording PC values,
|
|
|
|
so that we can look up the PC directly. */
|
|
|
|
lowpc += base_address;
|
|
|
|
highpc += base_address;
|
|
|
|
|
|
|
|
return add_range (state, rdata, lowpc, highpc, error_callback, data, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call ADD_RANGE for each range read from .debug_ranges, as used in
|
|
|
|
DWARF versions 2 through 4. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_ranges_from_ranges (
|
|
|
|
struct backtrace_state *state,
|
|
|
|
const struct dwarf_sections *dwarf_sections,
|
|
|
|
uintptr_t base_address, int is_bigendian,
|
|
|
|
struct unit *u, uint64_t base,
|
|
|
|
const struct pcrange *pcrange,
|
|
|
|
int (*add_range) (struct backtrace_state *state, void *rdata,
|
|
|
|
uint64_t lowpc, uint64_t highpc,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
void *vec),
|
|
|
|
void *rdata,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
void *vec)
|
|
|
|
{
|
|
|
|
struct dwarf_buf ranges_buf;
|
2019-12-10 04:41:49 +01:00
|
|
|
|
|
|
|
if (pcrange->ranges >= dwarf_sections->size[DEBUG_RANGES])
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
error_callback (data, "ranges offset out of range", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ranges_buf.name = ".debug_ranges";
|
2019-12-10 04:41:49 +01:00
|
|
|
ranges_buf.start = dwarf_sections->data[DEBUG_RANGES];
|
|
|
|
ranges_buf.buf = dwarf_sections->data[DEBUG_RANGES] + pcrange->ranges;
|
|
|
|
ranges_buf.left = dwarf_sections->size[DEBUG_RANGES] - pcrange->ranges;
|
2012-09-17 18:38:38 +02:00
|
|
|
ranges_buf.is_bigendian = is_bigendian;
|
|
|
|
ranges_buf.error_callback = error_callback;
|
|
|
|
ranges_buf.data = data;
|
|
|
|
ranges_buf.reported_underflow = 0;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t high;
|
|
|
|
|
|
|
|
if (ranges_buf.reported_underflow)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
low = read_address (&ranges_buf, u->addrsize);
|
|
|
|
high = read_address (&ranges_buf, u->addrsize);
|
|
|
|
|
|
|
|
if (low == 0 && high == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (is_highest_address (low, u->addrsize))
|
|
|
|
base = high;
|
|
|
|
else
|
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
if (!add_range (state, rdata,
|
|
|
|
low + base + base_address,
|
|
|
|
high + base + base_address,
|
|
|
|
error_callback, data, vec))
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ranges_buf.reported_underflow)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* Call ADD_RANGE for each range read from .debug_rnglists, as used in
|
|
|
|
DWARF version 5. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_ranges_from_rnglists (
|
|
|
|
struct backtrace_state *state,
|
|
|
|
const struct dwarf_sections *dwarf_sections,
|
|
|
|
uintptr_t base_address, int is_bigendian,
|
|
|
|
struct unit *u, uint64_t base,
|
|
|
|
const struct pcrange *pcrange,
|
|
|
|
int (*add_range) (struct backtrace_state *state, void *rdata,
|
|
|
|
uint64_t lowpc, uint64_t highpc,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
void *vec),
|
|
|
|
void *rdata,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
void *vec)
|
|
|
|
{
|
|
|
|
uint64_t offset;
|
|
|
|
struct dwarf_buf rnglists_buf;
|
|
|
|
|
|
|
|
if (!pcrange->ranges_is_index)
|
|
|
|
offset = pcrange->ranges;
|
|
|
|
else
|
|
|
|
offset = u->rnglists_base + pcrange->ranges * (u->is_dwarf64 ? 8 : 4);
|
|
|
|
if (offset >= dwarf_sections->size[DEBUG_RNGLISTS])
|
|
|
|
{
|
|
|
|
error_callback (data, "rnglists offset out of range", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rnglists_buf.name = ".debug_rnglists";
|
|
|
|
rnglists_buf.start = dwarf_sections->data[DEBUG_RNGLISTS];
|
|
|
|
rnglists_buf.buf = dwarf_sections->data[DEBUG_RNGLISTS] + offset;
|
|
|
|
rnglists_buf.left = dwarf_sections->size[DEBUG_RNGLISTS] - offset;
|
|
|
|
rnglists_buf.is_bigendian = is_bigendian;
|
|
|
|
rnglists_buf.error_callback = error_callback;
|
|
|
|
rnglists_buf.data = data;
|
|
|
|
rnglists_buf.reported_underflow = 0;
|
|
|
|
|
|
|
|
if (pcrange->ranges_is_index)
|
|
|
|
{
|
|
|
|
offset = read_offset (&rnglists_buf, u->is_dwarf64);
|
|
|
|
offset += u->rnglists_base;
|
|
|
|
if (offset >= dwarf_sections->size[DEBUG_RNGLISTS])
|
|
|
|
{
|
|
|
|
error_callback (data, "rnglists index offset out of range", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rnglists_buf.buf = dwarf_sections->data[DEBUG_RNGLISTS] + offset;
|
|
|
|
rnglists_buf.left = dwarf_sections->size[DEBUG_RNGLISTS] - offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
unsigned char rle;
|
|
|
|
|
|
|
|
rle = read_byte (&rnglists_buf);
|
|
|
|
if (rle == DW_RLE_end_of_list)
|
|
|
|
break;
|
|
|
|
switch (rle)
|
|
|
|
{
|
|
|
|
case DW_RLE_base_addressx:
|
|
|
|
{
|
|
|
|
uint64_t index;
|
|
|
|
|
|
|
|
index = read_uleb128 (&rnglists_buf);
|
|
|
|
if (!resolve_addr_index (dwarf_sections, u->addr_base,
|
|
|
|
u->addrsize, is_bigendian, index,
|
|
|
|
error_callback, data, &base))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_RLE_startx_endx:
|
|
|
|
{
|
|
|
|
uint64_t index;
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t high;
|
|
|
|
|
|
|
|
index = read_uleb128 (&rnglists_buf);
|
|
|
|
if (!resolve_addr_index (dwarf_sections, u->addr_base,
|
|
|
|
u->addrsize, is_bigendian, index,
|
|
|
|
error_callback, data, &low))
|
|
|
|
return 0;
|
|
|
|
index = read_uleb128 (&rnglists_buf);
|
|
|
|
if (!resolve_addr_index (dwarf_sections, u->addr_base,
|
|
|
|
u->addrsize, is_bigendian, index,
|
|
|
|
error_callback, data, &high))
|
|
|
|
return 0;
|
|
|
|
if (!add_range (state, rdata, low + base_address,
|
|
|
|
high + base_address, error_callback, data,
|
|
|
|
vec))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_RLE_startx_length:
|
|
|
|
{
|
|
|
|
uint64_t index;
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t length;
|
|
|
|
|
|
|
|
index = read_uleb128 (&rnglists_buf);
|
|
|
|
if (!resolve_addr_index (dwarf_sections, u->addr_base,
|
|
|
|
u->addrsize, is_bigendian, index,
|
|
|
|
error_callback, data, &low))
|
|
|
|
return 0;
|
|
|
|
length = read_uleb128 (&rnglists_buf);
|
|
|
|
low += base_address;
|
|
|
|
if (!add_range (state, rdata, low, low + length,
|
|
|
|
error_callback, data, vec))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_RLE_offset_pair:
|
|
|
|
{
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t high;
|
|
|
|
|
|
|
|
low = read_uleb128 (&rnglists_buf);
|
|
|
|
high = read_uleb128 (&rnglists_buf);
|
|
|
|
if (!add_range (state, rdata, low + base + base_address,
|
|
|
|
high + base + base_address,
|
|
|
|
error_callback, data, vec))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_RLE_base_address:
|
|
|
|
base = read_address (&rnglists_buf, u->addrsize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_RLE_start_end:
|
|
|
|
{
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t high;
|
|
|
|
|
|
|
|
low = read_address (&rnglists_buf, u->addrsize);
|
|
|
|
high = read_address (&rnglists_buf, u->addrsize);
|
|
|
|
if (!add_range (state, rdata, low + base_address,
|
|
|
|
high + base_address, error_callback, data,
|
|
|
|
vec))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_RLE_start_length:
|
|
|
|
{
|
|
|
|
uint64_t low;
|
|
|
|
uint64_t length;
|
|
|
|
|
|
|
|
low = read_address (&rnglists_buf, u->addrsize);
|
|
|
|
length = read_uleb128 (&rnglists_buf);
|
|
|
|
low += base_address;
|
|
|
|
if (!add_range (state, rdata, low, low + length,
|
|
|
|
error_callback, data, vec))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (&rnglists_buf, "unrecognized DW_RLE value", -1);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rnglists_buf.reported_underflow)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call ADD_RANGE for each lowpc/highpc pair in PCRANGE. RDATA is
|
|
|
|
passed to ADD_RANGE, and is either a struct unit * or a struct
|
|
|
|
function *. VEC is the vector we are adding ranges to, and is
|
|
|
|
either a struct unit_addrs_vector * or a struct function_vector *.
|
|
|
|
Returns 1 on success, 0 on error. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
add_ranges (struct backtrace_state *state,
|
|
|
|
const struct dwarf_sections *dwarf_sections,
|
|
|
|
uintptr_t base_address, int is_bigendian,
|
|
|
|
struct unit *u, uint64_t base, const struct pcrange *pcrange,
|
|
|
|
int (*add_range) (struct backtrace_state *state, void *rdata,
|
|
|
|
uint64_t lowpc, uint64_t highpc,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data, void *vec),
|
|
|
|
void *rdata,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
void *vec)
|
|
|
|
{
|
|
|
|
if (pcrange->have_lowpc && pcrange->have_highpc)
|
|
|
|
return add_low_high_range (state, dwarf_sections, base_address,
|
|
|
|
is_bigendian, u, pcrange, add_range, rdata,
|
|
|
|
error_callback, data, vec);
|
|
|
|
|
|
|
|
if (!pcrange->have_ranges)
|
|
|
|
{
|
|
|
|
/* Did not find any address ranges to add. */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (u->version < 5)
|
|
|
|
return add_ranges_from_ranges (state, dwarf_sections, base_address,
|
|
|
|
is_bigendian, u, base, pcrange, add_range,
|
|
|
|
rdata, error_callback, data, vec);
|
|
|
|
else
|
|
|
|
return add_ranges_from_rnglists (state, dwarf_sections, base_address,
|
|
|
|
is_bigendian, u, base, pcrange, add_range,
|
|
|
|
rdata, error_callback, data, vec);
|
|
|
|
}
|
|
|
|
|
2013-11-28 17:19:57 +01:00
|
|
|
/* Find the address range covered by a compilation unit, reading from
|
|
|
|
UNIT_BUF and adding values to U. Returns 1 if all data could be
|
|
|
|
read, 0 if there is some error. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
2013-11-28 17:19:57 +01:00
|
|
|
find_address_ranges (struct backtrace_state *state, uintptr_t base_address,
|
2016-09-11 15:44:07 +02:00
|
|
|
struct dwarf_buf *unit_buf,
|
2019-12-10 04:41:49 +01:00
|
|
|
const struct dwarf_sections *dwarf_sections,
|
2019-01-17 01:07:53 +01:00
|
|
|
int is_bigendian, struct dwarf_data *altlink,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
2019-01-17 14:42:09 +01:00
|
|
|
struct unit *u, struct unit_addrs_vector *addrs,
|
|
|
|
enum dwarf_tag *unit_tag)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2013-11-28 17:19:57 +01:00
|
|
|
while (unit_buf->left > 0)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
uint64_t code;
|
2013-11-28 17:19:57 +01:00
|
|
|
const struct abbrev *abbrev;
|
2019-12-10 04:41:49 +01:00
|
|
|
struct pcrange pcrange;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
struct attr_val name_val;
|
|
|
|
int have_name_val;
|
|
|
|
struct attr_val comp_dir_val;
|
|
|
|
int have_comp_dir_val;
|
2013-11-28 17:19:57 +01:00
|
|
|
size_t i;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2013-11-28 17:19:57 +01:00
|
|
|
code = read_uleb128 (unit_buf);
|
|
|
|
if (code == 0)
|
|
|
|
return 1;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2013-11-28 17:19:57 +01:00
|
|
|
abbrev = lookup_abbrev (&u->abbrevs, code, error_callback, data);
|
2012-09-17 18:38:38 +02:00
|
|
|
if (abbrev == NULL)
|
2013-11-28 17:19:57 +01:00
|
|
|
return 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2019-01-17 14:42:09 +01:00
|
|
|
if (unit_tag != NULL)
|
|
|
|
*unit_tag = abbrev->tag;
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
memset (&pcrange, 0, sizeof pcrange);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
memset (&name_val, 0, sizeof name_val);
|
|
|
|
have_name_val = 0;
|
|
|
|
memset (&comp_dir_val, 0, sizeof comp_dir_val);
|
|
|
|
have_comp_dir_val = 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
for (i = 0; i < abbrev->num_attrs; ++i)
|
|
|
|
{
|
|
|
|
struct attr_val val;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!read_attribute (abbrev->attrs[i].form, abbrev->attrs[i].val,
|
|
|
|
unit_buf, u->is_dwarf64, u->version,
|
|
|
|
u->addrsize, dwarf_sections, altlink, &val))
|
2013-11-28 17:19:57 +01:00
|
|
|
return 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
switch (abbrev->attrs[i].name)
|
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
case DW_AT_low_pc: case DW_AT_high_pc: case DW_AT_ranges:
|
|
|
|
update_pcrange (&abbrev->attrs[i], &val, &pcrange);
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
case DW_AT_stmt_list:
|
2022-02-17 05:18:45 +01:00
|
|
|
if ((abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
2013-11-28 17:19:57 +01:00
|
|
|
&& (val.encoding == ATTR_VAL_UINT
|
|
|
|
|| val.encoding == ATTR_VAL_REF_SECTION))
|
|
|
|
u->lineoff = val.u.uint;
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
2013-01-17 02:20:28 +01:00
|
|
|
case DW_AT_name:
|
2022-02-17 05:18:45 +01:00
|
|
|
if (abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
{
|
|
|
|
name_val = val;
|
|
|
|
have_name_val = 1;
|
|
|
|
}
|
2013-01-17 02:20:28 +01:00
|
|
|
break;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
case DW_AT_comp_dir:
|
2022-02-17 05:18:45 +01:00
|
|
|
if (abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
{
|
|
|
|
comp_dir_val = val;
|
|
|
|
have_comp_dir_val = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_str_offsets_base:
|
2022-02-17 05:18:45 +01:00
|
|
|
if ((abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
&& val.encoding == ATTR_VAL_REF_SECTION)
|
|
|
|
u->str_offsets_base = val.u.uint;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_addr_base:
|
2022-02-17 05:18:45 +01:00
|
|
|
if ((abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
&& val.encoding == ATTR_VAL_REF_SECTION)
|
|
|
|
u->addr_base = val.u.uint;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_rnglists_base:
|
2022-02-17 05:18:45 +01:00
|
|
|
if ((abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
&& val.encoding == ATTR_VAL_REF_SECTION)
|
|
|
|
u->rnglists_base = val.u.uint;
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
// Resolve strings after we're sure that we have seen
|
|
|
|
// DW_AT_str_offsets_base.
|
|
|
|
if (have_name_val)
|
|
|
|
{
|
|
|
|
if (!resolve_string (dwarf_sections, u->is_dwarf64, is_bigendian,
|
|
|
|
u->str_offsets_base, &name_val,
|
|
|
|
error_callback, data, &u->filename))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (have_comp_dir_val)
|
|
|
|
{
|
|
|
|
if (!resolve_string (dwarf_sections, u->is_dwarf64, is_bigendian,
|
|
|
|
u->str_offsets_base, &comp_dir_val,
|
|
|
|
error_callback, data, &u->comp_dir))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-28 17:19:57 +01:00
|
|
|
if (abbrev->tag == DW_TAG_compile_unit
|
2022-02-17 05:18:45 +01:00
|
|
|
|| abbrev->tag == DW_TAG_subprogram
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
if (!add_ranges (state, dwarf_sections, base_address,
|
|
|
|
is_bigendian, u, pcrange.lowpc, &pcrange,
|
|
|
|
add_unit_addr, (void *) u, error_callback, data,
|
|
|
|
(void *) addrs))
|
|
|
|
return 0;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
2022-02-17 05:18:45 +01:00
|
|
|
/* If we found the PC range in the DW_TAG_compile_unit or
|
|
|
|
DW_TAG_skeleton_unit, we can stop now. */
|
|
|
|
if ((abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
2019-12-10 04:41:49 +01:00
|
|
|
&& (pcrange.have_ranges
|
|
|
|
|| (pcrange.have_lowpc && pcrange.have_highpc)))
|
2013-11-28 17:19:57 +01:00
|
|
|
return 1;
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
2013-11-28 17:19:57 +01:00
|
|
|
|
|
|
|
if (abbrev->has_children)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2013-11-28 17:19:57 +01:00
|
|
|
if (!find_address_ranges (state, base_address, unit_buf,
|
2019-12-10 04:41:49 +01:00
|
|
|
dwarf_sections, is_bigendian, altlink,
|
|
|
|
error_callback, data, u, addrs, NULL))
|
2013-11-28 17:19:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build a mapping from address ranges to the compilation units where
|
|
|
|
the line number information for that range can be found. Returns 1
|
|
|
|
on success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
build_address_map (struct backtrace_state *state, uintptr_t base_address,
|
2019-12-05 03:20:11 +01:00
|
|
|
const struct dwarf_sections *dwarf_sections,
|
2019-01-17 01:07:53 +01:00
|
|
|
int is_bigendian, struct dwarf_data *altlink,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
2019-01-17 14:42:09 +01:00
|
|
|
struct unit_addrs_vector *addrs,
|
|
|
|
struct unit_vector *unit_vec)
|
2013-11-28 17:19:57 +01:00
|
|
|
{
|
|
|
|
struct dwarf_buf info;
|
2018-12-28 04:43:26 +01:00
|
|
|
struct backtrace_vector units;
|
|
|
|
size_t units_count;
|
|
|
|
size_t i;
|
|
|
|
struct unit **pu;
|
2019-01-23 11:22:43 +01:00
|
|
|
size_t unit_offset = 0;
|
2020-09-09 03:18:48 +02:00
|
|
|
struct unit_addrs *pa;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
|
|
|
memset (&addrs->vec, 0, sizeof addrs->vec);
|
2019-01-17 14:42:09 +01:00
|
|
|
memset (&unit_vec->vec, 0, sizeof unit_vec->vec);
|
2013-11-28 17:19:57 +01:00
|
|
|
addrs->count = 0;
|
2019-01-17 14:42:09 +01:00
|
|
|
unit_vec->count = 0;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
|
|
|
/* Read through the .debug_info section. FIXME: Should we use the
|
|
|
|
.debug_aranges section? gdb and addr2line don't use it, but I'm
|
|
|
|
not sure why. */
|
|
|
|
|
|
|
|
info.name = ".debug_info";
|
2019-12-05 03:20:11 +01:00
|
|
|
info.start = dwarf_sections->data[DEBUG_INFO];
|
|
|
|
info.buf = info.start;
|
|
|
|
info.left = dwarf_sections->size[DEBUG_INFO];
|
2013-11-28 17:19:57 +01:00
|
|
|
info.is_bigendian = is_bigendian;
|
|
|
|
info.error_callback = error_callback;
|
|
|
|
info.data = data;
|
|
|
|
info.reported_underflow = 0;
|
|
|
|
|
2018-12-28 04:43:26 +01:00
|
|
|
memset (&units, 0, sizeof units);
|
|
|
|
units_count = 0;
|
|
|
|
|
2013-11-28 17:19:57 +01:00
|
|
|
while (info.left > 0)
|
|
|
|
{
|
|
|
|
const unsigned char *unit_data_start;
|
|
|
|
uint64_t len;
|
|
|
|
int is_dwarf64;
|
|
|
|
struct dwarf_buf unit_buf;
|
|
|
|
int version;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
int unit_type;
|
2013-11-28 17:19:57 +01:00
|
|
|
uint64_t abbrev_offset;
|
|
|
|
int addrsize;
|
|
|
|
struct unit *u;
|
2019-01-17 14:42:09 +01:00
|
|
|
enum dwarf_tag unit_tag;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
|
|
|
if (info.reported_underflow)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
unit_data_start = info.buf;
|
|
|
|
|
2018-11-22 01:06:27 +01:00
|
|
|
len = read_initial_length (&info, &is_dwarf64);
|
2013-11-28 17:19:57 +01:00
|
|
|
unit_buf = info;
|
|
|
|
unit_buf.left = len;
|
|
|
|
|
|
|
|
if (!advance (&info, len))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
version = read_uint16 (&unit_buf);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (version < 2 || version > 5)
|
2013-11-28 17:19:57 +01:00
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (&unit_buf, "unrecognized DWARF version", -1);
|
2013-11-28 17:19:57 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (version < 5)
|
|
|
|
unit_type = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit_type = read_byte (&unit_buf);
|
|
|
|
if (unit_type == DW_UT_type || unit_type == DW_UT_split_type)
|
|
|
|
{
|
|
|
|
/* This unit doesn't have anything we need. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 04:43:26 +01:00
|
|
|
pu = ((struct unit **)
|
|
|
|
backtrace_vector_grow (state, sizeof (struct unit *),
|
|
|
|
error_callback, data, &units));
|
|
|
|
if (pu == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
2013-11-28 17:19:57 +01:00
|
|
|
u = ((struct unit *)
|
|
|
|
backtrace_alloc (state, sizeof *u, error_callback, data));
|
|
|
|
if (u == NULL)
|
|
|
|
goto fail;
|
2018-12-28 04:43:26 +01:00
|
|
|
|
|
|
|
*pu = u;
|
|
|
|
++units_count;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (version < 5)
|
|
|
|
addrsize = 0; /* Set below. */
|
|
|
|
else
|
|
|
|
addrsize = read_byte (&unit_buf);
|
|
|
|
|
2018-12-28 04:43:41 +01:00
|
|
|
memset (&u->abbrevs, 0, sizeof u->abbrevs);
|
|
|
|
abbrev_offset = read_offset (&unit_buf, is_dwarf64);
|
2019-12-05 03:20:11 +01:00
|
|
|
if (!read_abbrevs (state, abbrev_offset,
|
|
|
|
dwarf_sections->data[DEBUG_ABBREV],
|
|
|
|
dwarf_sections->size[DEBUG_ABBREV],
|
2018-12-28 04:43:41 +01:00
|
|
|
is_bigendian, error_callback, data, &u->abbrevs))
|
|
|
|
goto fail;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (version < 5)
|
|
|
|
addrsize = read_byte (&unit_buf);
|
|
|
|
|
|
|
|
switch (unit_type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case DW_UT_compile: case DW_UT_partial:
|
|
|
|
break;
|
|
|
|
case DW_UT_skeleton: case DW_UT_split_compile:
|
|
|
|
read_uint64 (&unit_buf); /* dwo_id */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-12-28 04:43:41 +01:00
|
|
|
|
2019-01-17 14:42:09 +01:00
|
|
|
u->low_offset = unit_offset;
|
|
|
|
unit_offset += len + (is_dwarf64 ? 12 : 4);
|
|
|
|
u->high_offset = unit_offset;
|
2013-11-28 17:19:57 +01:00
|
|
|
u->unit_data = unit_buf.buf;
|
|
|
|
u->unit_data_len = unit_buf.left;
|
|
|
|
u->unit_data_offset = unit_buf.buf - unit_data_start;
|
|
|
|
u->version = version;
|
|
|
|
u->is_dwarf64 = is_dwarf64;
|
|
|
|
u->addrsize = addrsize;
|
|
|
|
u->filename = NULL;
|
|
|
|
u->comp_dir = NULL;
|
|
|
|
u->abs_filename = NULL;
|
|
|
|
u->lineoff = 0;
|
2022-02-16 20:35:00 +01:00
|
|
|
u->str_offsets_base = 0;
|
|
|
|
u->addr_base = 0;
|
|
|
|
u->rnglists_base = 0;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
|
|
|
/* The actual line number mappings will be read as needed. */
|
|
|
|
u->lines = NULL;
|
|
|
|
u->lines_count = 0;
|
|
|
|
u->function_addrs = NULL;
|
|
|
|
u->function_addrs_count = 0;
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
if (!find_address_ranges (state, base_address, &unit_buf, dwarf_sections,
|
2019-01-17 01:07:53 +01:00
|
|
|
is_bigendian, altlink, error_callback, data,
|
2019-01-17 14:42:09 +01:00
|
|
|
u, addrs, &unit_tag))
|
2018-12-28 04:43:26 +01:00
|
|
|
goto fail;
|
2013-11-28 17:19:57 +01:00
|
|
|
|
|
|
|
if (unit_buf.reported_underflow)
|
2018-12-28 04:43:26 +01:00
|
|
|
goto fail;
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
if (info.reported_underflow)
|
|
|
|
goto fail;
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Add a trailing addrs entry, but don't include it in addrs->count. */
|
|
|
|
pa = ((struct unit_addrs *)
|
|
|
|
backtrace_vector_grow (state, sizeof (struct unit_addrs),
|
|
|
|
error_callback, data, &addrs->vec));
|
|
|
|
if (pa == NULL)
|
|
|
|
goto fail;
|
|
|
|
pa->low = 0;
|
|
|
|
--pa->low;
|
|
|
|
pa->high = pa->low;
|
|
|
|
pa->u = NULL;
|
|
|
|
|
2019-01-17 14:42:09 +01:00
|
|
|
unit_vec->vec = units;
|
|
|
|
unit_vec->count = units_count;
|
2012-09-17 18:38:38 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
fail:
|
2018-12-28 04:43:26 +01:00
|
|
|
if (units_count > 0)
|
|
|
|
{
|
|
|
|
pu = (struct unit **) units.base;
|
|
|
|
for (i = 0; i < units_count; i++)
|
|
|
|
{
|
|
|
|
free_abbrevs (state, &pu[i]->abbrevs, error_callback, data);
|
|
|
|
backtrace_free (state, pu[i], sizeof **pu, error_callback, data);
|
|
|
|
}
|
|
|
|
backtrace_vector_free (state, &units, error_callback, data);
|
|
|
|
}
|
2018-12-28 04:43:15 +01:00
|
|
|
if (addrs->count > 0)
|
|
|
|
{
|
|
|
|
backtrace_vector_free (state, &addrs->vec, error_callback, data);
|
|
|
|
addrs->count = 0;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a new mapping to the vector of line mappings that we are
|
|
|
|
building. Returns 1 on success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
2012-10-09 20:20:45 +02:00
|
|
|
add_line (struct backtrace_state *state, struct dwarf_data *ddata,
|
|
|
|
uintptr_t pc, const char *filename, int lineno,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
2012-09-17 18:38:38 +02:00
|
|
|
struct line_vector *vec)
|
|
|
|
{
|
|
|
|
struct line *ln;
|
|
|
|
|
|
|
|
/* If we are adding the same mapping, ignore it. This can happen
|
|
|
|
when using discriminators. */
|
|
|
|
if (vec->count > 0)
|
|
|
|
{
|
|
|
|
ln = (struct line *) vec->vec.base + (vec->count - 1);
|
|
|
|
if (pc == ln->pc && filename == ln->filename && lineno == ln->lineno)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ln = ((struct line *)
|
|
|
|
backtrace_vector_grow (state, sizeof (struct line), error_callback,
|
|
|
|
data, &vec->vec));
|
|
|
|
if (ln == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-09 20:20:45 +02:00
|
|
|
/* Add in the base address here, so that we can look up the PC
|
|
|
|
directly. */
|
|
|
|
ln->pc = pc + ddata->base_address;
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
ln->filename = filename;
|
|
|
|
ln->lineno = lineno;
|
2015-06-12 02:01:50 +02:00
|
|
|
ln->idx = vec->count;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
++vec->count;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-05-19 18:07:24 +02:00
|
|
|
/* Free the line header information. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
free_line_header (struct backtrace_state *state, struct line_header *hdr,
|
|
|
|
backtrace_error_callback error_callback, void *data)
|
|
|
|
{
|
2017-05-19 18:07:24 +02:00
|
|
|
if (hdr->dirs_count != 0)
|
|
|
|
backtrace_free (state, hdr->dirs, hdr->dirs_count * sizeof (const char *),
|
|
|
|
error_callback, data);
|
2012-09-17 18:38:38 +02:00
|
|
|
backtrace_free (state, hdr->filenames,
|
|
|
|
hdr->filenames_count * sizeof (char *),
|
|
|
|
error_callback, data);
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
/* Read the directories and file names for a line header for version
|
|
|
|
2, setting fields in HDR. Return 1 on success, 0 on failure. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
read_v2_paths (struct backtrace_state *state, struct unit *u,
|
|
|
|
struct dwarf_buf *hdr_buf, struct line_header *hdr)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
const unsigned char *p;
|
|
|
|
const unsigned char *pend;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* Count the number of directory entries. */
|
|
|
|
hdr->dirs_count = 0;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
p = hdr_buf->buf;
|
|
|
|
pend = p + hdr_buf->left;
|
2012-09-17 18:38:38 +02:00
|
|
|
while (p < pend && *p != '\0')
|
|
|
|
{
|
|
|
|
p += strnlen((const char *) p, pend - p) + 1;
|
|
|
|
++hdr->dirs_count;
|
|
|
|
}
|
|
|
|
|
2021-01-18 23:38:10 +01:00
|
|
|
/* The index of the first entry in the list of directories is 1. Index 0 is
|
|
|
|
used for the current directory of the compilation. To simplify index
|
|
|
|
handling, we set entry 0 to the compilation unit directory. */
|
|
|
|
++hdr->dirs_count;
|
|
|
|
hdr->dirs = ((const char **)
|
|
|
|
backtrace_alloc (state,
|
|
|
|
hdr->dirs_count * sizeof (const char *),
|
|
|
|
hdr_buf->error_callback,
|
|
|
|
hdr_buf->data));
|
|
|
|
if (hdr->dirs == NULL)
|
|
|
|
return 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2021-01-18 23:38:10 +01:00
|
|
|
hdr->dirs[0] = u->comp_dir;
|
|
|
|
i = 1;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
while (*hdr_buf->buf != '\0')
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (hdr_buf->reported_underflow)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
hdr->dirs[i] = read_string (hdr_buf);
|
2018-11-21 09:31:04 +01:00
|
|
|
if (hdr->dirs[i] == NULL)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
2018-11-21 09:31:04 +01:00
|
|
|
++i;
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!advance (hdr_buf, 1))
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Count the number of file entries. */
|
|
|
|
hdr->filenames_count = 0;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
p = hdr_buf->buf;
|
|
|
|
pend = p + hdr_buf->left;
|
2012-09-17 18:38:38 +02:00
|
|
|
while (p < pend && *p != '\0')
|
|
|
|
{
|
|
|
|
p += strnlen ((const char *) p, pend - p) + 1;
|
|
|
|
p += leb128_len (p);
|
|
|
|
p += leb128_len (p);
|
|
|
|
p += leb128_len (p);
|
|
|
|
++hdr->filenames_count;
|
|
|
|
}
|
|
|
|
|
2021-01-18 23:38:10 +01:00
|
|
|
/* The index of the first entry in the list of file names is 1. Index 0 is
|
|
|
|
used for the DW_AT_name of the compilation unit. To simplify index
|
|
|
|
handling, we set entry 0 to the compilation unit file name. */
|
|
|
|
++hdr->filenames_count;
|
2012-09-17 18:38:38 +02:00
|
|
|
hdr->filenames = ((const char **)
|
|
|
|
backtrace_alloc (state,
|
|
|
|
hdr->filenames_count * sizeof (char *),
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
hdr_buf->error_callback,
|
|
|
|
hdr_buf->data));
|
2012-09-17 18:38:38 +02:00
|
|
|
if (hdr->filenames == NULL)
|
|
|
|
return 0;
|
2021-01-18 23:38:10 +01:00
|
|
|
hdr->filenames[0] = u->filename;
|
|
|
|
i = 1;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
while (*hdr_buf->buf != '\0')
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
const char *filename;
|
|
|
|
uint64_t dir_index;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (hdr_buf->reported_underflow)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
filename = read_string (hdr_buf);
|
2018-11-21 09:31:04 +01:00
|
|
|
if (filename == NULL)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
dir_index = read_uleb128 (hdr_buf);
|
2013-01-25 23:36:11 +01:00
|
|
|
if (IS_ABSOLUTE_PATH (filename)
|
2021-01-18 23:38:10 +01:00
|
|
|
|| (dir_index < hdr->dirs_count && hdr->dirs[dir_index] == NULL))
|
2012-09-17 18:38:38 +02:00
|
|
|
hdr->filenames[i] = filename;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *dir;
|
|
|
|
size_t dir_len;
|
|
|
|
size_t filename_len;
|
|
|
|
char *s;
|
|
|
|
|
2021-01-18 23:38:10 +01:00
|
|
|
if (dir_index < hdr->dirs_count)
|
|
|
|
dir = hdr->dirs[dir_index];
|
2012-09-17 18:38:38 +02:00
|
|
|
else
|
|
|
|
{
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
dwarf_buf_error (hdr_buf,
|
2012-09-17 18:38:38 +02:00
|
|
|
("invalid directory index in "
|
2021-03-02 22:45:56 +01:00
|
|
|
"line number program header"),
|
|
|
|
0);
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dir_len = strlen (dir);
|
|
|
|
filename_len = strlen (filename);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
s = ((char *) backtrace_alloc (state, dir_len + filename_len + 2,
|
|
|
|
hdr_buf->error_callback,
|
|
|
|
hdr_buf->data));
|
2012-09-17 18:38:38 +02:00
|
|
|
if (s == NULL)
|
|
|
|
return 0;
|
|
|
|
memcpy (s, dir, dir_len);
|
|
|
|
/* FIXME: If we are on a DOS-based file system, and the
|
|
|
|
directory or the file name use backslashes, then we
|
|
|
|
should use a backslash here. */
|
|
|
|
s[dir_len] = '/';
|
|
|
|
memcpy (s + dir_len + 1, filename, filename_len + 1);
|
|
|
|
hdr->filenames[i] = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore the modification time and size. */
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
read_uleb128 (hdr_buf);
|
|
|
|
read_uleb128 (hdr_buf);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a single version 5 LNCT entry for a directory or file name in a
|
|
|
|
line header. Sets *STRING to the resulting name, ignoring other
|
|
|
|
data. Return 1 on success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_lnct (struct backtrace_state *state, struct dwarf_data *ddata,
|
|
|
|
struct unit *u, struct dwarf_buf *hdr_buf,
|
|
|
|
const struct line_header *hdr, size_t formats_count,
|
|
|
|
const struct line_header_format *formats, const char **string)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
const char *dir;
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
dir = NULL;
|
|
|
|
path = NULL;
|
|
|
|
for (i = 0; i < formats_count; i++)
|
|
|
|
{
|
|
|
|
struct attr_val val;
|
|
|
|
|
|
|
|
if (!read_attribute (formats[i].form, 0, hdr_buf, u->is_dwarf64,
|
|
|
|
u->version, hdr->addrsize, &ddata->dwarf_sections,
|
|
|
|
ddata->altlink, &val))
|
|
|
|
return 0;
|
|
|
|
switch (formats[i].lnct)
|
|
|
|
{
|
|
|
|
case DW_LNCT_path:
|
|
|
|
if (!resolve_string (&ddata->dwarf_sections, u->is_dwarf64,
|
|
|
|
ddata->is_bigendian, u->str_offsets_base,
|
|
|
|
&val, hdr_buf->error_callback, hdr_buf->data,
|
|
|
|
&path))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case DW_LNCT_directory_index:
|
|
|
|
if (val.encoding == ATTR_VAL_UINT)
|
|
|
|
{
|
|
|
|
if (val.u.uint >= hdr->dirs_count)
|
|
|
|
{
|
|
|
|
dwarf_buf_error (hdr_buf,
|
|
|
|
("invalid directory index in "
|
2021-03-02 22:45:56 +01:00
|
|
|
"line number program header"),
|
|
|
|
0);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dir = hdr->dirs[val.u.uint];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* We don't care about timestamps or sizes or hashes. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
{
|
|
|
|
dwarf_buf_error (hdr_buf,
|
2021-03-02 22:45:56 +01:00
|
|
|
"missing file name in line number program header",
|
|
|
|
0);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir == NULL)
|
|
|
|
*string = path;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t dir_len;
|
|
|
|
size_t path_len;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
dir_len = strlen (dir);
|
|
|
|
path_len = strlen (path);
|
|
|
|
s = (char *) backtrace_alloc (state, dir_len + path_len + 2,
|
|
|
|
hdr_buf->error_callback, hdr_buf->data);
|
|
|
|
if (s == NULL)
|
|
|
|
return 0;
|
|
|
|
memcpy (s, dir, dir_len);
|
|
|
|
/* FIXME: If we are on a DOS-based file system, and the
|
|
|
|
directory or the path name use backslashes, then we should
|
|
|
|
use a backslash here. */
|
|
|
|
s[dir_len] = '/';
|
|
|
|
memcpy (s + dir_len + 1, path, path_len + 1);
|
|
|
|
*string = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a set of DWARF 5 line header format entries, setting *PCOUNT
|
|
|
|
and *PPATHS. Return 1 on success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_line_header_format_entries (struct backtrace_state *state,
|
|
|
|
struct dwarf_data *ddata,
|
|
|
|
struct unit *u,
|
|
|
|
struct dwarf_buf *hdr_buf,
|
|
|
|
struct line_header *hdr,
|
|
|
|
size_t *pcount,
|
|
|
|
const char ***ppaths)
|
|
|
|
{
|
|
|
|
size_t formats_count;
|
|
|
|
struct line_header_format *formats;
|
|
|
|
size_t paths_count;
|
|
|
|
const char **paths;
|
|
|
|
size_t i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
formats_count = read_byte (hdr_buf);
|
|
|
|
if (formats_count == 0)
|
|
|
|
formats = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
formats = ((struct line_header_format *)
|
|
|
|
backtrace_alloc (state,
|
|
|
|
(formats_count
|
|
|
|
* sizeof (struct line_header_format)),
|
|
|
|
hdr_buf->error_callback,
|
|
|
|
hdr_buf->data));
|
|
|
|
if (formats == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < formats_count; i++)
|
|
|
|
{
|
|
|
|
formats[i].lnct = (int) read_uleb128(hdr_buf);
|
|
|
|
formats[i].form = (enum dwarf_form) read_uleb128 (hdr_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
paths_count = read_uleb128 (hdr_buf);
|
|
|
|
if (paths_count == 0)
|
|
|
|
{
|
|
|
|
*pcount = 0;
|
|
|
|
*ppaths = NULL;
|
|
|
|
ret = 1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
paths = ((const char **)
|
|
|
|
backtrace_alloc (state, paths_count * sizeof (const char *),
|
|
|
|
hdr_buf->error_callback, hdr_buf->data));
|
|
|
|
if (paths == NULL)
|
|
|
|
{
|
|
|
|
ret = 0;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
for (i = 0; i < paths_count; i++)
|
|
|
|
{
|
|
|
|
if (!read_lnct (state, ddata, u, hdr_buf, hdr, formats_count,
|
|
|
|
formats, &paths[i]))
|
|
|
|
{
|
|
|
|
backtrace_free (state, paths,
|
|
|
|
paths_count * sizeof (const char *),
|
|
|
|
hdr_buf->error_callback, hdr_buf->data);
|
|
|
|
ret = 0;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcount = paths_count;
|
|
|
|
*ppaths = paths;
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
if (formats != NULL)
|
|
|
|
backtrace_free (state, formats,
|
|
|
|
formats_count * sizeof (struct line_header_format),
|
|
|
|
hdr_buf->error_callback, hdr_buf->data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the line header. Return 1 on success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_line_header (struct backtrace_state *state, struct dwarf_data *ddata,
|
|
|
|
struct unit *u, int is_dwarf64, struct dwarf_buf *line_buf,
|
|
|
|
struct line_header *hdr)
|
|
|
|
{
|
|
|
|
uint64_t hdrlen;
|
|
|
|
struct dwarf_buf hdr_buf;
|
|
|
|
|
|
|
|
hdr->version = read_uint16 (line_buf);
|
|
|
|
if (hdr->version < 2 || hdr->version > 5)
|
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (line_buf, "unsupported line number version", -1);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr->version < 5)
|
|
|
|
hdr->addrsize = u->addrsize;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hdr->addrsize = read_byte (line_buf);
|
|
|
|
/* We could support a non-zero segment_selector_size but I doubt
|
|
|
|
we'll ever see it. */
|
|
|
|
if (read_byte (line_buf) != 0)
|
|
|
|
{
|
|
|
|
dwarf_buf_error (line_buf,
|
2021-03-02 22:45:56 +01:00
|
|
|
"non-zero segment_selector_size not supported",
|
|
|
|
-1);
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hdrlen = read_offset (line_buf, is_dwarf64);
|
|
|
|
|
|
|
|
hdr_buf = *line_buf;
|
|
|
|
hdr_buf.left = hdrlen;
|
|
|
|
|
|
|
|
if (!advance (line_buf, hdrlen))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
hdr->min_insn_len = read_byte (&hdr_buf);
|
|
|
|
if (hdr->version < 4)
|
|
|
|
hdr->max_ops_per_insn = 1;
|
|
|
|
else
|
|
|
|
hdr->max_ops_per_insn = read_byte (&hdr_buf);
|
|
|
|
|
|
|
|
/* We don't care about default_is_stmt. */
|
|
|
|
read_byte (&hdr_buf);
|
|
|
|
|
|
|
|
hdr->line_base = read_sbyte (&hdr_buf);
|
|
|
|
hdr->line_range = read_byte (&hdr_buf);
|
|
|
|
|
|
|
|
hdr->opcode_base = read_byte (&hdr_buf);
|
|
|
|
hdr->opcode_lengths = hdr_buf.buf;
|
|
|
|
if (!advance (&hdr_buf, hdr->opcode_base - 1))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (hdr->version < 5)
|
|
|
|
{
|
|
|
|
if (!read_v2_paths (state, u, &hdr_buf, hdr))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!read_line_header_format_entries (state, ddata, u, &hdr_buf, hdr,
|
|
|
|
&hdr->dirs_count,
|
|
|
|
&hdr->dirs))
|
|
|
|
return 0;
|
|
|
|
if (!read_line_header_format_entries (state, ddata, u, &hdr_buf, hdr,
|
|
|
|
&hdr->filenames_count,
|
|
|
|
&hdr->filenames))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
if (hdr_buf.reported_underflow)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the line program, adding line mappings to VEC. Return 1 on
|
|
|
|
success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
2012-10-09 20:20:45 +02:00
|
|
|
read_line_program (struct backtrace_state *state, struct dwarf_data *ddata,
|
2021-01-18 23:38:10 +01:00
|
|
|
const struct line_header *hdr, struct dwarf_buf *line_buf,
|
|
|
|
struct line_vector *vec)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
uint64_t address;
|
|
|
|
unsigned int op_index;
|
|
|
|
const char *reset_filename;
|
|
|
|
const char *filename;
|
|
|
|
int lineno;
|
|
|
|
|
|
|
|
address = 0;
|
|
|
|
op_index = 0;
|
2021-01-18 23:38:10 +01:00
|
|
|
if (hdr->filenames_count > 1)
|
|
|
|
reset_filename = hdr->filenames[1];
|
2012-09-17 18:38:38 +02:00
|
|
|
else
|
|
|
|
reset_filename = "";
|
|
|
|
filename = reset_filename;
|
|
|
|
lineno = 1;
|
|
|
|
while (line_buf->left > 0)
|
|
|
|
{
|
|
|
|
unsigned int op;
|
|
|
|
|
|
|
|
op = read_byte (line_buf);
|
|
|
|
if (op >= hdr->opcode_base)
|
|
|
|
{
|
|
|
|
unsigned int advance;
|
|
|
|
|
|
|
|
/* Special opcode. */
|
|
|
|
op -= hdr->opcode_base;
|
|
|
|
advance = op / hdr->line_range;
|
|
|
|
address += (hdr->min_insn_len * (op_index + advance)
|
|
|
|
/ hdr->max_ops_per_insn);
|
|
|
|
op_index = (op_index + advance) % hdr->max_ops_per_insn;
|
|
|
|
lineno += hdr->line_base + (int) (op % hdr->line_range);
|
2012-10-09 20:20:45 +02:00
|
|
|
add_line (state, ddata, address, filename, lineno,
|
|
|
|
line_buf->error_callback, line_buf->data, vec);
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
else if (op == DW_LNS_extended_op)
|
|
|
|
{
|
|
|
|
uint64_t len;
|
|
|
|
|
|
|
|
len = read_uleb128 (line_buf);
|
|
|
|
op = read_byte (line_buf);
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case DW_LNE_end_sequence:
|
|
|
|
/* FIXME: Should we mark the high PC here? It seems
|
|
|
|
that we already have that information from the
|
|
|
|
compilation unit. */
|
|
|
|
address = 0;
|
|
|
|
op_index = 0;
|
|
|
|
filename = reset_filename;
|
|
|
|
lineno = 1;
|
|
|
|
break;
|
|
|
|
case DW_LNE_set_address:
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
address = read_address (line_buf, hdr->addrsize);
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
case DW_LNE_define_file:
|
|
|
|
{
|
|
|
|
const char *f;
|
|
|
|
unsigned int dir_index;
|
|
|
|
|
2018-11-21 09:31:04 +01:00
|
|
|
f = read_string (line_buf);
|
|
|
|
if (f == NULL)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
dir_index = read_uleb128 (line_buf);
|
|
|
|
/* Ignore that time and length. */
|
|
|
|
read_uleb128 (line_buf);
|
|
|
|
read_uleb128 (line_buf);
|
|
|
|
if (IS_ABSOLUTE_PATH (f))
|
|
|
|
filename = f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *dir;
|
|
|
|
size_t dir_len;
|
|
|
|
size_t f_len;
|
|
|
|
char *p;
|
|
|
|
|
2021-01-18 23:38:10 +01:00
|
|
|
if (dir_index < hdr->dirs_count)
|
|
|
|
dir = hdr->dirs[dir_index];
|
2012-09-17 18:38:38 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dwarf_buf_error (line_buf,
|
|
|
|
("invalid directory index "
|
2021-03-02 22:45:56 +01:00
|
|
|
"in line number program"),
|
|
|
|
0);
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dir_len = strlen (dir);
|
|
|
|
f_len = strlen (f);
|
|
|
|
p = ((char *)
|
|
|
|
backtrace_alloc (state, dir_len + f_len + 2,
|
|
|
|
line_buf->error_callback,
|
|
|
|
line_buf->data));
|
|
|
|
if (p == NULL)
|
|
|
|
return 0;
|
|
|
|
memcpy (p, dir, dir_len);
|
|
|
|
/* FIXME: If we are on a DOS-based file system,
|
|
|
|
and the directory or the file name use
|
|
|
|
backslashes, then we should use a backslash
|
|
|
|
here. */
|
|
|
|
p[dir_len] = '/';
|
|
|
|
memcpy (p + dir_len + 1, f, f_len + 1);
|
|
|
|
filename = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DW_LNE_set_discriminator:
|
|
|
|
/* We don't care about discriminators. */
|
|
|
|
read_uleb128 (line_buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!advance (line_buf, len - 1))
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case DW_LNS_copy:
|
2012-10-09 20:20:45 +02:00
|
|
|
add_line (state, ddata, address, filename, lineno,
|
2012-09-17 18:38:38 +02:00
|
|
|
line_buf->error_callback, line_buf->data, vec);
|
|
|
|
break;
|
|
|
|
case DW_LNS_advance_pc:
|
|
|
|
{
|
|
|
|
uint64_t advance;
|
|
|
|
|
|
|
|
advance = read_uleb128 (line_buf);
|
|
|
|
address += (hdr->min_insn_len * (op_index + advance)
|
|
|
|
/ hdr->max_ops_per_insn);
|
|
|
|
op_index = (op_index + advance) % hdr->max_ops_per_insn;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DW_LNS_advance_line:
|
|
|
|
lineno += (int) read_sleb128 (line_buf);
|
|
|
|
break;
|
|
|
|
case DW_LNS_set_file:
|
|
|
|
{
|
|
|
|
uint64_t fileno;
|
|
|
|
|
|
|
|
fileno = read_uleb128 (line_buf);
|
2021-03-03 03:14:55 +01:00
|
|
|
if (fileno >= hdr->filenames_count)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2021-03-03 03:14:55 +01:00
|
|
|
dwarf_buf_error (line_buf,
|
|
|
|
("invalid file number in "
|
|
|
|
"line number program"),
|
|
|
|
0);
|
|
|
|
return 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
2021-03-03 03:14:55 +01:00
|
|
|
filename = hdr->filenames[fileno];
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DW_LNS_set_column:
|
|
|
|
read_uleb128 (line_buf);
|
|
|
|
break;
|
|
|
|
case DW_LNS_negate_stmt:
|
|
|
|
break;
|
|
|
|
case DW_LNS_set_basic_block:
|
|
|
|
break;
|
|
|
|
case DW_LNS_const_add_pc:
|
|
|
|
{
|
|
|
|
unsigned int advance;
|
|
|
|
|
|
|
|
op = 255 - hdr->opcode_base;
|
|
|
|
advance = op / hdr->line_range;
|
|
|
|
address += (hdr->min_insn_len * (op_index + advance)
|
|
|
|
/ hdr->max_ops_per_insn);
|
|
|
|
op_index = (op_index + advance) % hdr->max_ops_per_insn;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DW_LNS_fixed_advance_pc:
|
|
|
|
address += read_uint16 (line_buf);
|
|
|
|
op_index = 0;
|
|
|
|
break;
|
|
|
|
case DW_LNS_set_prologue_end:
|
|
|
|
break;
|
|
|
|
case DW_LNS_set_epilogue_begin:
|
|
|
|
break;
|
|
|
|
case DW_LNS_set_isa:
|
|
|
|
read_uleb128 (line_buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = hdr->opcode_lengths[op - 1]; i > 0; --i)
|
|
|
|
read_uleb128 (line_buf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the line number information for a compilation unit. Returns 1
|
|
|
|
on success, 0 on failure. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_line_info (struct backtrace_state *state, struct dwarf_data *ddata,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
struct unit *u, struct line_header *hdr, struct line **lines,
|
|
|
|
size_t *lines_count)
|
|
|
|
{
|
|
|
|
struct line_vector vec;
|
|
|
|
struct dwarf_buf line_buf;
|
|
|
|
uint64_t len;
|
|
|
|
int is_dwarf64;
|
|
|
|
struct line *ln;
|
|
|
|
|
|
|
|
memset (&vec.vec, 0, sizeof vec.vec);
|
|
|
|
vec.count = 0;
|
|
|
|
|
|
|
|
memset (hdr, 0, sizeof *hdr);
|
|
|
|
|
|
|
|
if (u->lineoff != (off_t) (size_t) u->lineoff
|
2019-12-05 03:20:11 +01:00
|
|
|
|| (size_t) u->lineoff >= ddata->dwarf_sections.size[DEBUG_LINE])
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
error_callback (data, "unit line offset out of range", 0);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
line_buf.name = ".debug_line";
|
2019-12-05 03:20:11 +01:00
|
|
|
line_buf.start = ddata->dwarf_sections.data[DEBUG_LINE];
|
|
|
|
line_buf.buf = ddata->dwarf_sections.data[DEBUG_LINE] + u->lineoff;
|
|
|
|
line_buf.left = ddata->dwarf_sections.size[DEBUG_LINE] - u->lineoff;
|
2012-09-17 18:38:38 +02:00
|
|
|
line_buf.is_bigendian = ddata->is_bigendian;
|
|
|
|
line_buf.error_callback = error_callback;
|
|
|
|
line_buf.data = data;
|
|
|
|
line_buf.reported_underflow = 0;
|
|
|
|
|
2018-11-22 01:06:27 +01:00
|
|
|
len = read_initial_length (&line_buf, &is_dwarf64);
|
2012-09-17 18:38:38 +02:00
|
|
|
line_buf.left = len;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!read_line_header (state, ddata, u, is_dwarf64, &line_buf, hdr))
|
2012-09-17 18:38:38 +02:00
|
|
|
goto fail;
|
|
|
|
|
2021-01-18 23:38:10 +01:00
|
|
|
if (!read_line_program (state, ddata, hdr, &line_buf, &vec))
|
2012-09-17 18:38:38 +02:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (line_buf.reported_underflow)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (vec.count == 0)
|
|
|
|
{
|
|
|
|
/* This is not a failure in the sense of a generating an error,
|
|
|
|
but it is a failure in that sense that we have no useful
|
|
|
|
information. */
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate one extra entry at the end. */
|
|
|
|
ln = ((struct line *)
|
|
|
|
backtrace_vector_grow (state, sizeof (struct line), error_callback,
|
|
|
|
data, &vec.vec));
|
|
|
|
if (ln == NULL)
|
|
|
|
goto fail;
|
|
|
|
ln->pc = (uintptr_t) -1;
|
|
|
|
ln->filename = NULL;
|
|
|
|
ln->lineno = 0;
|
2015-06-12 02:01:50 +02:00
|
|
|
ln->idx = 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
if (!backtrace_vector_release (state, &vec.vec, error_callback, data))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ln = (struct line *) vec.vec.base;
|
2014-03-07 06:07:56 +01:00
|
|
|
backtrace_qsort (ln, vec.count, sizeof (struct line), line_compare);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
*lines = ln;
|
|
|
|
*lines_count = vec.count;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
fail:
|
2018-11-30 09:43:50 +01:00
|
|
|
backtrace_vector_free (state, &vec.vec, error_callback, data);
|
2012-09-17 18:38:38 +02:00
|
|
|
free_line_header (state, hdr, error_callback, data);
|
|
|
|
*lines = (struct line *) (uintptr_t) -1;
|
|
|
|
*lines_count = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-16 21:47:02 +01:00
|
|
|
static const char *read_referenced_name (struct dwarf_data *, struct unit *,
|
|
|
|
uint64_t, backtrace_error_callback,
|
|
|
|
void *);
|
|
|
|
|
|
|
|
/* Read the name of a function from a DIE referenced by ATTR with VAL. */
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
read_referenced_name_from_attr (struct dwarf_data *ddata, struct unit *u,
|
|
|
|
struct attr *attr, struct attr_val *val,
|
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
switch (attr->name)
|
|
|
|
{
|
|
|
|
case DW_AT_abstract_origin:
|
|
|
|
case DW_AT_specification:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-08 06:55:44 +01:00
|
|
|
if (attr->form == DW_FORM_ref_sig8)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (val->encoding == ATTR_VAL_REF_INFO)
|
2019-01-16 21:47:02 +01:00
|
|
|
{
|
2019-02-08 06:55:44 +01:00
|
|
|
struct unit *unit
|
|
|
|
= find_unit (ddata->units, ddata->units_count,
|
|
|
|
val->u.uint);
|
|
|
|
if (unit == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
uint64_t offset = val->u.uint - unit->low_offset;
|
|
|
|
return read_referenced_name (ddata, unit, offset, error_callback, data);
|
2019-01-16 21:47:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (val->encoding == ATTR_VAL_UINT
|
|
|
|
|| val->encoding == ATTR_VAL_REF_UNIT)
|
|
|
|
return read_referenced_name (ddata, u, val->u.uint, error_callback, data);
|
|
|
|
|
2019-01-17 14:42:20 +01:00
|
|
|
if (val->encoding == ATTR_VAL_REF_ALT_INFO)
|
|
|
|
{
|
|
|
|
struct unit *alt_unit
|
|
|
|
= find_unit (ddata->altlink->units, ddata->altlink->units_count,
|
|
|
|
val->u.uint);
|
|
|
|
if (alt_unit == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
uint64_t offset = val->u.uint - alt_unit->low_offset;
|
|
|
|
return read_referenced_name (ddata->altlink, alt_unit, offset,
|
|
|
|
error_callback, data);
|
|
|
|
}
|
|
|
|
|
2019-01-16 21:47:02 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
/* Read the name of a function from a DIE referenced by a
|
|
|
|
DW_AT_abstract_origin or DW_AT_specification tag. OFFSET is within
|
|
|
|
the same compilation unit. */
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
read_referenced_name (struct dwarf_data *ddata, struct unit *u,
|
|
|
|
uint64_t offset, backtrace_error_callback error_callback,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct dwarf_buf unit_buf;
|
|
|
|
uint64_t code;
|
|
|
|
const struct abbrev *abbrev;
|
|
|
|
const char *ret;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* OFFSET is from the start of the data for this compilation unit.
|
|
|
|
U->unit_data is the data, but it starts U->unit_data_offset bytes
|
|
|
|
from the beginning. */
|
|
|
|
|
|
|
|
if (offset < u->unit_data_offset
|
|
|
|
|| offset - u->unit_data_offset >= u->unit_data_len)
|
|
|
|
{
|
|
|
|
error_callback (data,
|
|
|
|
"abstract origin or specification out of range",
|
|
|
|
0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset -= u->unit_data_offset;
|
|
|
|
|
|
|
|
unit_buf.name = ".debug_info";
|
2019-12-05 03:20:11 +01:00
|
|
|
unit_buf.start = ddata->dwarf_sections.data[DEBUG_INFO];
|
2012-09-17 18:38:38 +02:00
|
|
|
unit_buf.buf = u->unit_data + offset;
|
|
|
|
unit_buf.left = u->unit_data_len - offset;
|
|
|
|
unit_buf.is_bigendian = ddata->is_bigendian;
|
|
|
|
unit_buf.error_callback = error_callback;
|
|
|
|
unit_buf.data = data;
|
|
|
|
unit_buf.reported_underflow = 0;
|
|
|
|
|
|
|
|
code = read_uleb128 (&unit_buf);
|
|
|
|
if (code == 0)
|
|
|
|
{
|
2021-03-02 22:45:56 +01:00
|
|
|
dwarf_buf_error (&unit_buf,
|
|
|
|
"invalid abstract origin or specification",
|
|
|
|
0);
|
2012-09-17 18:38:38 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
abbrev = lookup_abbrev (&u->abbrevs, code, error_callback, data);
|
|
|
|
if (abbrev == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = NULL;
|
|
|
|
for (i = 0; i < abbrev->num_attrs; ++i)
|
|
|
|
{
|
|
|
|
struct attr_val val;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!read_attribute (abbrev->attrs[i].form, abbrev->attrs[i].val,
|
|
|
|
&unit_buf, u->is_dwarf64, u->version, u->addrsize,
|
|
|
|
&ddata->dwarf_sections, ddata->altlink, &val))
|
2012-09-17 18:38:38 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
switch (abbrev->attrs[i].name)
|
|
|
|
{
|
|
|
|
case DW_AT_name:
|
2019-01-16 08:46:56 +01:00
|
|
|
/* Third name preference: don't override. A name we found in some
|
|
|
|
other way, will normally be more useful -- e.g., this name is
|
|
|
|
normally not mangled. */
|
|
|
|
if (ret != NULL)
|
|
|
|
break;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!resolve_string (&ddata->dwarf_sections, u->is_dwarf64,
|
|
|
|
ddata->is_bigendian, u->str_offsets_base,
|
|
|
|
&val, error_callback, data, &ret))
|
|
|
|
return NULL;
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_linkage_name:
|
|
|
|
case DW_AT_MIPS_linkage_name:
|
2019-01-16 08:46:56 +01:00
|
|
|
/* First name preference: override all. */
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
s = NULL;
|
|
|
|
if (!resolve_string (&ddata->dwarf_sections, u->is_dwarf64,
|
|
|
|
ddata->is_bigendian, u->str_offsets_base,
|
|
|
|
&val, error_callback, data, &s))
|
|
|
|
return NULL;
|
|
|
|
if (s != NULL)
|
|
|
|
return s;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_specification:
|
2019-01-16 08:46:56 +01:00
|
|
|
/* Second name preference: override DW_AT_name, don't override
|
|
|
|
DW_AT_linkage_name. */
|
2019-01-16 21:47:02 +01:00
|
|
|
{
|
|
|
|
const char *name;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2019-01-16 21:47:02 +01:00
|
|
|
name = read_referenced_name_from_attr (ddata, u, &abbrev->attrs[i],
|
|
|
|
&val, error_callback, data);
|
|
|
|
if (name != NULL)
|
|
|
|
ret = name;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
/* Add a range to a unit that maps to a function. This is called via
|
|
|
|
add_ranges. Returns 1 on success, 0 on error. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
2019-12-10 04:41:49 +01:00
|
|
|
add_function_range (struct backtrace_state *state, void *rdata,
|
|
|
|
uint64_t lowpc, uint64_t highpc,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
void *pvec)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
struct function *function = (struct function *) rdata;
|
|
|
|
struct function_vector *vec = (struct function_vector *) pvec;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct function_addrs *p;
|
|
|
|
|
|
|
|
if (vec->count > 0)
|
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
p = (struct function_addrs *) vec->vec.base + (vec->count - 1);
|
2012-09-17 18:38:38 +02:00
|
|
|
if ((lowpc == p->high || lowpc == p->high + 1)
|
|
|
|
&& function == p->function)
|
|
|
|
{
|
|
|
|
if (highpc > p->high)
|
|
|
|
p->high = highpc;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = ((struct function_addrs *)
|
|
|
|
backtrace_vector_grow (state, sizeof (struct function_addrs),
|
|
|
|
error_callback, data, &vec->vec));
|
|
|
|
if (p == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p->low = lowpc;
|
|
|
|
p->high = highpc;
|
|
|
|
p->function = function;
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
++vec->count;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read one entry plus all its children. Add function addresses to
|
|
|
|
VEC. Returns 1 on success, 0 on error. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
read_function_entry (struct backtrace_state *state, struct dwarf_data *ddata,
|
|
|
|
struct unit *u, uint64_t base, struct dwarf_buf *unit_buf,
|
|
|
|
const struct line_header *lhdr,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
2015-08-14 00:56:01 +02:00
|
|
|
struct function_vector *vec_function,
|
|
|
|
struct function_vector *vec_inlined)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
while (unit_buf->left > 0)
|
|
|
|
{
|
|
|
|
uint64_t code;
|
|
|
|
const struct abbrev *abbrev;
|
|
|
|
int is_function;
|
|
|
|
struct function *function;
|
2015-08-14 00:56:01 +02:00
|
|
|
struct function_vector *vec;
|
2012-09-17 18:38:38 +02:00
|
|
|
size_t i;
|
2019-12-10 04:41:49 +01:00
|
|
|
struct pcrange pcrange;
|
2019-01-16 08:46:56 +01:00
|
|
|
int have_linkage_name;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
code = read_uleb128 (unit_buf);
|
|
|
|
if (code == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
abbrev = lookup_abbrev (&u->abbrevs, code, error_callback, data);
|
|
|
|
if (abbrev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
is_function = (abbrev->tag == DW_TAG_subprogram
|
|
|
|
|| abbrev->tag == DW_TAG_entry_point
|
|
|
|
|| abbrev->tag == DW_TAG_inlined_subroutine);
|
|
|
|
|
2015-08-14 00:56:01 +02:00
|
|
|
if (abbrev->tag == DW_TAG_inlined_subroutine)
|
|
|
|
vec = vec_inlined;
|
|
|
|
else
|
|
|
|
vec = vec_function;
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
function = NULL;
|
|
|
|
if (is_function)
|
|
|
|
{
|
|
|
|
function = ((struct function *)
|
|
|
|
backtrace_alloc (state, sizeof *function,
|
|
|
|
error_callback, data));
|
|
|
|
if (function == NULL)
|
|
|
|
return 0;
|
|
|
|
memset (function, 0, sizeof *function);
|
|
|
|
}
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
memset (&pcrange, 0, sizeof pcrange);
|
2019-01-16 08:46:56 +01:00
|
|
|
have_linkage_name = 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
for (i = 0; i < abbrev->num_attrs; ++i)
|
|
|
|
{
|
|
|
|
struct attr_val val;
|
|
|
|
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!read_attribute (abbrev->attrs[i].form, abbrev->attrs[i].val,
|
|
|
|
unit_buf, u->is_dwarf64, u->version,
|
|
|
|
u->addrsize, &ddata->dwarf_sections,
|
2019-01-17 01:07:53 +01:00
|
|
|
ddata->altlink, &val))
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The compile unit sets the base address for any address
|
|
|
|
ranges in the function entries. */
|
2022-02-17 05:18:45 +01:00
|
|
|
if ((abbrev->tag == DW_TAG_compile_unit
|
|
|
|
|| abbrev->tag == DW_TAG_skeleton_unit)
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
&& abbrev->attrs[i].name == DW_AT_low_pc)
|
|
|
|
{
|
|
|
|
if (val.encoding == ATTR_VAL_ADDRESS)
|
|
|
|
base = val.u.uint;
|
|
|
|
else if (val.encoding == ATTR_VAL_ADDRESS_INDEX)
|
|
|
|
{
|
|
|
|
if (!resolve_addr_index (&ddata->dwarf_sections,
|
|
|
|
u->addr_base, u->addrsize,
|
|
|
|
ddata->is_bigendian, val.u.uint,
|
|
|
|
error_callback, data, &base))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
if (is_function)
|
|
|
|
{
|
|
|
|
switch (abbrev->attrs[i].name)
|
|
|
|
{
|
|
|
|
case DW_AT_call_file:
|
|
|
|
if (val.encoding == ATTR_VAL_UINT)
|
|
|
|
{
|
2021-03-03 03:14:55 +01:00
|
|
|
if (val.u.uint >= lhdr->filenames_count)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2021-03-03 03:14:55 +01:00
|
|
|
dwarf_buf_error (unit_buf,
|
|
|
|
("invalid file number in "
|
|
|
|
"DW_AT_call_file attribute"),
|
|
|
|
0);
|
|
|
|
return 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
2021-03-03 03:14:55 +01:00
|
|
|
function->caller_filename = lhdr->filenames[val.u.uint];
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_call_line:
|
|
|
|
if (val.encoding == ATTR_VAL_UINT)
|
|
|
|
function->caller_lineno = val.u.uint;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_abstract_origin:
|
|
|
|
case DW_AT_specification:
|
2019-01-16 08:46:56 +01:00
|
|
|
/* Second name preference: override DW_AT_name, don't override
|
|
|
|
DW_AT_linkage_name. */
|
|
|
|
if (have_linkage_name)
|
|
|
|
break;
|
2019-01-16 21:47:02 +01:00
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
name
|
|
|
|
= read_referenced_name_from_attr (ddata, u,
|
|
|
|
&abbrev->attrs[i], &val,
|
|
|
|
error_callback, data);
|
|
|
|
if (name != NULL)
|
|
|
|
function->name = name;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_name:
|
2019-01-16 08:46:56 +01:00
|
|
|
/* Third name preference: don't override. */
|
|
|
|
if (function->name != NULL)
|
|
|
|
break;
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
if (!resolve_string (&ddata->dwarf_sections, u->is_dwarf64,
|
|
|
|
ddata->is_bigendian,
|
|
|
|
u->str_offsets_base, &val,
|
|
|
|
error_callback, data, &function->name))
|
|
|
|
return 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_AT_linkage_name:
|
|
|
|
case DW_AT_MIPS_linkage_name:
|
2019-01-16 08:46:56 +01:00
|
|
|
/* First name preference: override all. */
|
libbacktrace: add DWARF 5 support
* dwarf.c (struct attr): Add val field.
(enum attr_val_encoding): Add ATTR_VAL_ADDDRESS_INDEX,
ATTR_VAL_STRING_INDEX, ATTR_VAL_RNGLISTS_INDEX.
(struct line_header): Add addrsize field.
(struct line_header_format): Define.
(struct unit): Add str_offsets_base, addr_base, and rnglists_base
fields.
(read_uint24): New static function.
(read_attribute): Add implicit_val parameter. Replace dwarf_str
and dwarf_str_size parameters with dwarf_sections parameter. Add
support for new DWARF 5 forms. Change all callers.
(resolve_string): New static function.
(resolve_addr_index): Likewise.
(read_abbrevs): Support DW_FORM_implicit_const.
(struct pcrange): Add lowpc_is_addr_index, highpc_is_addr_Index,
and ranges_is_index fields.
(update_pcrange): Support DWARF 5 encodings.
(add_high_low_range): New static function, split out of
add_ranges.
(add_ranges_from_ranges): Likewise.
(add_ranges_from_rnglists): New static function.
(add_ranges): Just call new helper functions.
(find_address_ranges): Use resolve_string for strings, after
reading all attributes. Handle new DWARF 5 attributes.
(build_address_map): Support DWARF 5 compilation units.
(read_v2_paths): New static function, split out of
read_line_header.
(read_lnct): New static function.
(read_line_header_format_entries): Likewise.
(read_line_header): Add ddata parameter. Support DWARF 5 line
headers. Call new helper functions. Change all callers.
(read_line_program): Use addrsize from line program header. Don't
special case directory index 0 for DWARF 5.
(read_referenced_name): Use resolve_string.
(read_function_entry): Handle DWARF 5 encodings. Use
resolve_string.
* internal.h (enum dwarf_section): Add DEBUG_ADDR,
DEBUG_STR_OFFSETS, DEBUG_LINE_STR, DEBUG_RNGLISTS.
* elf.c (dwarf_section_names): Add new section names.
* pecoff.c (dwarf_section_names): Likewise.
* xcoff.c (xcoff_add): Clear dwarf_sections before setting
fields.
* configure.ac: Define HAVE_DWARF5 automake conditional.
* Makefile.am (dwarf5_SOURCES): New variable if HAVE_DWARF5.
(dwarf5_CFLAGS, dwarf5_LDADD): Likewise.
(dwarf5_alloc_SOURCES, dwarf5_alloc_CFLAGS): Likewise.
(dwarf5_alloc_LDADD): Likewise.
(BUILDTESTS): Add dwarf5 tests if HAVE_DWARF5.
(CLEANFILES, clean-local): Define.
From-SVN: r279380
2019-12-13 21:04:47 +01:00
|
|
|
{
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
s = NULL;
|
|
|
|
if (!resolve_string (&ddata->dwarf_sections, u->is_dwarf64,
|
|
|
|
ddata->is_bigendian,
|
|
|
|
u->str_offsets_base, &val,
|
|
|
|
error_callback, data, &s))
|
|
|
|
return 0;
|
|
|
|
if (s != NULL)
|
|
|
|
{
|
|
|
|
function->name = s;
|
|
|
|
have_linkage_name = 1;
|
|
|
|
}
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
|
2019-12-10 04:41:49 +01:00
|
|
|
case DW_AT_low_pc: case DW_AT_high_pc: case DW_AT_ranges:
|
|
|
|
update_pcrange (&abbrev->attrs[i], &val, &pcrange);
|
2012-09-17 18:38:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we couldn't find a name for the function, we have no use
|
|
|
|
for it. */
|
|
|
|
if (is_function && function->name == NULL)
|
|
|
|
{
|
|
|
|
backtrace_free (state, function, sizeof *function,
|
|
|
|
error_callback, data);
|
|
|
|
is_function = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_function)
|
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
if (pcrange.have_ranges
|
|
|
|
|| (pcrange.have_lowpc && pcrange.have_highpc))
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
2019-12-10 04:41:49 +01:00
|
|
|
if (!add_ranges (state, &ddata->dwarf_sections,
|
|
|
|
ddata->base_address, ddata->is_bigendian,
|
|
|
|
u, base, &pcrange, add_function_range,
|
|
|
|
(void *) function, error_callback, data,
|
|
|
|
(void *) vec))
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
backtrace_free (state, function, sizeof *function,
|
|
|
|
error_callback, data);
|
|
|
|
is_function = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abbrev->has_children)
|
|
|
|
{
|
|
|
|
if (!is_function)
|
|
|
|
{
|
|
|
|
if (!read_function_entry (state, ddata, u, base, unit_buf, lhdr,
|
2015-08-14 00:56:01 +02:00
|
|
|
error_callback, data, vec_function,
|
|
|
|
vec_inlined))
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct function_vector fvec;
|
|
|
|
|
|
|
|
/* Gather any information for inlined functions in
|
|
|
|
FVEC. */
|
|
|
|
|
|
|
|
memset (&fvec, 0, sizeof fvec);
|
|
|
|
|
|
|
|
if (!read_function_entry (state, ddata, u, base, unit_buf, lhdr,
|
2015-08-14 00:56:01 +02:00
|
|
|
error_callback, data, vec_function,
|
|
|
|
&fvec))
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (fvec.count > 0)
|
|
|
|
{
|
2020-09-09 03:18:48 +02:00
|
|
|
struct function_addrs *p;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct function_addrs *faddrs;
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Allocate a trailing entry, but don't include it
|
|
|
|
in fvec.count. */
|
|
|
|
p = ((struct function_addrs *)
|
|
|
|
backtrace_vector_grow (state,
|
|
|
|
sizeof (struct function_addrs),
|
|
|
|
error_callback, data,
|
|
|
|
&fvec.vec));
|
|
|
|
if (p == NULL)
|
|
|
|
return 0;
|
|
|
|
p->low = 0;
|
|
|
|
--p->low;
|
|
|
|
p->high = p->low;
|
|
|
|
p->function = NULL;
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
if (!backtrace_vector_release (state, &fvec.vec,
|
|
|
|
error_callback, data))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
faddrs = (struct function_addrs *) fvec.vec.base;
|
2014-03-07 06:07:56 +01:00
|
|
|
backtrace_qsort (faddrs, fvec.count,
|
|
|
|
sizeof (struct function_addrs),
|
|
|
|
function_addrs_compare);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
function->function_addrs = faddrs;
|
|
|
|
function->function_addrs_count = fvec.count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read function name information for a compilation unit. We look
|
|
|
|
through the whole unit looking for function tags. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_function_info (struct backtrace_state *state, struct dwarf_data *ddata,
|
|
|
|
const struct line_header *lhdr,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
struct unit *u, struct function_vector *fvec,
|
|
|
|
struct function_addrs **ret_addrs,
|
|
|
|
size_t *ret_addrs_count)
|
|
|
|
{
|
2013-01-31 18:50:47 +01:00
|
|
|
struct function_vector lvec;
|
|
|
|
struct function_vector *pfvec;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct dwarf_buf unit_buf;
|
2020-09-09 03:18:48 +02:00
|
|
|
struct function_addrs *p;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct function_addrs *addrs;
|
|
|
|
size_t addrs_count;
|
|
|
|
|
2013-01-31 18:50:47 +01:00
|
|
|
/* Use FVEC if it is not NULL. Otherwise use our own vector. */
|
|
|
|
if (fvec != NULL)
|
|
|
|
pfvec = fvec;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset (&lvec, 0, sizeof lvec);
|
|
|
|
pfvec = &lvec;
|
|
|
|
}
|
|
|
|
|
2012-09-17 18:38:38 +02:00
|
|
|
unit_buf.name = ".debug_info";
|
2019-12-05 03:20:11 +01:00
|
|
|
unit_buf.start = ddata->dwarf_sections.data[DEBUG_INFO];
|
2012-09-17 18:38:38 +02:00
|
|
|
unit_buf.buf = u->unit_data;
|
|
|
|
unit_buf.left = u->unit_data_len;
|
|
|
|
unit_buf.is_bigendian = ddata->is_bigendian;
|
|
|
|
unit_buf.error_callback = error_callback;
|
|
|
|
unit_buf.data = data;
|
|
|
|
unit_buf.reported_underflow = 0;
|
|
|
|
|
|
|
|
while (unit_buf.left > 0)
|
|
|
|
{
|
|
|
|
if (!read_function_entry (state, ddata, u, 0, &unit_buf, lhdr,
|
2015-08-14 00:56:01 +02:00
|
|
|
error_callback, data, pfvec, pfvec))
|
2012-09-17 18:38:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-31 18:50:47 +01:00
|
|
|
if (pfvec->count == 0)
|
2012-09-17 18:38:38 +02:00
|
|
|
return;
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Allocate a trailing entry, but don't include it in
|
|
|
|
pfvec->count. */
|
|
|
|
p = ((struct function_addrs *)
|
|
|
|
backtrace_vector_grow (state, sizeof (struct function_addrs),
|
|
|
|
error_callback, data, &pfvec->vec));
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
p->low = 0;
|
|
|
|
--p->low;
|
|
|
|
p->high = p->low;
|
|
|
|
p->function = NULL;
|
|
|
|
|
2013-01-31 18:50:47 +01:00
|
|
|
addrs_count = pfvec->count;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2013-01-31 18:50:47 +01:00
|
|
|
if (fvec == NULL)
|
|
|
|
{
|
|
|
|
if (!backtrace_vector_release (state, &lvec.vec, error_callback, data))
|
|
|
|
return;
|
2013-12-05 19:32:02 +01:00
|
|
|
addrs = (struct function_addrs *) pfvec->vec.base;
|
2013-01-31 18:50:47 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Finish this list of addresses, but leave the remaining space in
|
|
|
|
the vector available for the next function unit. */
|
2013-12-05 19:32:02 +01:00
|
|
|
addrs = ((struct function_addrs *)
|
|
|
|
backtrace_vector_finish (state, &fvec->vec,
|
|
|
|
error_callback, data));
|
|
|
|
if (addrs == NULL)
|
|
|
|
return;
|
2013-01-31 18:50:47 +01:00
|
|
|
fvec->count = 0;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2014-03-07 06:07:56 +01:00
|
|
|
backtrace_qsort (addrs, addrs_count, sizeof (struct function_addrs),
|
|
|
|
function_addrs_compare);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
*ret_addrs = addrs;
|
|
|
|
*ret_addrs_count = addrs_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if PC is inlined in FUNCTION. If it is, print out the inlined
|
|
|
|
information, and update FILENAME and LINENO for the caller.
|
|
|
|
Returns whatever CALLBACK returns, or 0 to keep going. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
report_inlined_functions (uintptr_t pc, struct function *function,
|
|
|
|
backtrace_full_callback callback, void *data,
|
|
|
|
const char **filename, int *lineno)
|
|
|
|
{
|
2020-09-09 03:18:48 +02:00
|
|
|
struct function_addrs *p;
|
|
|
|
struct function_addrs *match;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct function *inlined;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (function->function_addrs_count == 0)
|
|
|
|
return 0;
|
|
|
|
|
2020-09-23 02:27:46 +02:00
|
|
|
/* Our search isn't safe if pc == -1, as that is the sentinel
|
|
|
|
value. */
|
|
|
|
if (pc + 1 == 0)
|
|
|
|
return 0;
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
p = ((struct function_addrs *)
|
|
|
|
bsearch (&pc, function->function_addrs,
|
|
|
|
function->function_addrs_count,
|
|
|
|
sizeof (struct function_addrs),
|
|
|
|
function_addrs_search));
|
|
|
|
if (p == NULL)
|
2012-09-17 18:38:38 +02:00
|
|
|
return 0;
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Here pc >= p->low && pc < (p + 1)->low. The function_addrs are
|
2020-09-23 02:27:46 +02:00
|
|
|
sorted by low, so if pc > p->low we are at the end of a range of
|
|
|
|
function_addrs with the same low value. If pc == p->low walk
|
|
|
|
forward to the end of the range with that low value. Then walk
|
|
|
|
backward and use the first range that includes pc. */
|
|
|
|
while (pc == (p + 1)->low)
|
|
|
|
++p;
|
2020-09-09 03:18:48 +02:00
|
|
|
match = NULL;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (pc < p->high)
|
|
|
|
{
|
|
|
|
match = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == function->function_addrs)
|
|
|
|
break;
|
|
|
|
if ((p - 1)->low < p->low)
|
|
|
|
break;
|
|
|
|
--p;
|
|
|
|
}
|
|
|
|
if (match == NULL)
|
|
|
|
return 0;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
/* We found an inlined call. */
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
inlined = match->function;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
/* Report any calls inlined into this one. */
|
|
|
|
ret = report_inlined_functions (pc, inlined, callback, data,
|
|
|
|
filename, lineno);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Report this inlined call. */
|
|
|
|
ret = callback (data, pc, *filename, *lineno, inlined->name);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Our caller will report the caller of the inlined function; tell
|
|
|
|
it the appropriate filename and line number. */
|
|
|
|
*filename = inlined->caller_filename;
|
|
|
|
*lineno = inlined->caller_lineno;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 20:20:45 +02:00
|
|
|
/* Look for a PC in the DWARF mapping for one module. On success,
|
|
|
|
call CALLBACK and return whatever it returns. On error, call
|
|
|
|
ERROR_CALLBACK and return 0. Sets *FOUND to 1 if the PC is found,
|
|
|
|
0 if not. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
static int
|
2012-10-09 20:20:45 +02:00
|
|
|
dwarf_lookup_pc (struct backtrace_state *state, struct dwarf_data *ddata,
|
|
|
|
uintptr_t pc, backtrace_full_callback callback,
|
|
|
|
backtrace_error_callback error_callback, void *data,
|
|
|
|
int *found)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
struct unit_addrs *entry;
|
2020-09-09 03:18:48 +02:00
|
|
|
int found_entry;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct unit *u;
|
|
|
|
int new_data;
|
|
|
|
struct line *lines;
|
|
|
|
struct line *ln;
|
2020-09-09 03:18:48 +02:00
|
|
|
struct function_addrs *p;
|
|
|
|
struct function_addrs *fmatch;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct function *function;
|
|
|
|
const char *filename;
|
|
|
|
int lineno;
|
|
|
|
int ret;
|
|
|
|
|
2012-10-09 20:20:45 +02:00
|
|
|
*found = 1;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2020-09-23 02:27:46 +02:00
|
|
|
/* Find an address range that includes PC. Our search isn't safe if
|
|
|
|
PC == -1, as we use that as a sentinel value, so skip the search
|
|
|
|
in that case. */
|
|
|
|
entry = (ddata->addrs_count == 0 || pc + 1 == 0
|
2019-02-12 15:00:59 +01:00
|
|
|
? NULL
|
|
|
|
: bsearch (&pc, ddata->addrs, ddata->addrs_count,
|
|
|
|
sizeof (struct unit_addrs), unit_addrs_search));
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
if (entry == NULL)
|
2012-10-09 20:20:45 +02:00
|
|
|
{
|
|
|
|
*found = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Here pc >= entry->low && pc < (entry + 1)->low. The unit_addrs
|
2020-09-23 02:27:46 +02:00
|
|
|
are sorted by low, so if pc > p->low we are at the end of a range
|
|
|
|
of unit_addrs with the same low value. If pc == p->low walk
|
|
|
|
forward to the end of the range with that low value. Then walk
|
|
|
|
backward and use the first range that includes pc. */
|
|
|
|
while (pc == (entry + 1)->low)
|
|
|
|
++entry;
|
2020-09-09 03:18:48 +02:00
|
|
|
found_entry = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (pc < entry->high)
|
|
|
|
{
|
|
|
|
found_entry = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (entry == ddata->addrs)
|
|
|
|
break;
|
|
|
|
if ((entry - 1)->low < entry->low)
|
|
|
|
break;
|
|
|
|
--entry;
|
|
|
|
}
|
|
|
|
if (!found_entry)
|
|
|
|
{
|
|
|
|
*found = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
/* We need the lines, lines_count, function_addrs,
|
|
|
|
function_addrs_count fields of u. If they are not set, we need
|
|
|
|
to set them. When running in threaded mode, we need to allow for
|
|
|
|
the possibility that some other thread is setting them
|
|
|
|
simultaneously. */
|
|
|
|
|
|
|
|
u = entry->u;
|
|
|
|
lines = u->lines;
|
|
|
|
|
|
|
|
/* Skip units with no useful line number information by walking
|
|
|
|
backward. Useless line number information is marked by setting
|
|
|
|
lines == -1. */
|
|
|
|
while (entry > ddata->addrs
|
|
|
|
&& pc >= (entry - 1)->low
|
|
|
|
&& pc < (entry - 1)->high)
|
|
|
|
{
|
|
|
|
if (state->threaded)
|
2013-11-19 02:09:47 +01:00
|
|
|
lines = (struct line *) backtrace_atomic_load_pointer (&u->lines);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
if (lines != (struct line *) (uintptr_t) -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
--entry;
|
|
|
|
|
|
|
|
u = entry->u;
|
|
|
|
lines = u->lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->threaded)
|
2013-11-19 02:09:47 +01:00
|
|
|
lines = backtrace_atomic_load_pointer (&u->lines);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
new_data = 0;
|
|
|
|
if (lines == NULL)
|
|
|
|
{
|
2020-09-09 03:18:48 +02:00
|
|
|
struct function_addrs *function_addrs;
|
2012-09-17 18:38:38 +02:00
|
|
|
size_t function_addrs_count;
|
|
|
|
struct line_header lhdr;
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
/* We have never read the line information for this unit. Read
|
|
|
|
it now. */
|
|
|
|
|
|
|
|
function_addrs = NULL;
|
|
|
|
function_addrs_count = 0;
|
|
|
|
if (read_line_info (state, ddata, error_callback, data, entry->u, &lhdr,
|
|
|
|
&lines, &count))
|
|
|
|
{
|
2013-01-31 18:50:47 +01:00
|
|
|
struct function_vector *pfvec;
|
|
|
|
|
|
|
|
/* If not threaded, reuse DDATA->FVEC for better memory
|
|
|
|
consumption. */
|
|
|
|
if (state->threaded)
|
|
|
|
pfvec = NULL;
|
|
|
|
else
|
|
|
|
pfvec = &ddata->fvec;
|
2012-09-17 18:38:38 +02:00
|
|
|
read_function_info (state, ddata, &lhdr, error_callback, data,
|
2013-01-31 18:50:47 +01:00
|
|
|
entry->u, pfvec, &function_addrs,
|
2012-09-17 18:38:38 +02:00
|
|
|
&function_addrs_count);
|
|
|
|
free_line_header (state, &lhdr, error_callback, data);
|
|
|
|
new_data = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Atomically store the information we just read into the unit.
|
|
|
|
If another thread is simultaneously writing, it presumably
|
|
|
|
read the same information, and we don't care which one we
|
|
|
|
wind up with; we just leak the other one. We do have to
|
|
|
|
write the lines field last, so that the acquire-loads above
|
|
|
|
ensure that the other fields are set. */
|
|
|
|
|
|
|
|
if (!state->threaded)
|
|
|
|
{
|
|
|
|
u->lines_count = count;
|
|
|
|
u->function_addrs = function_addrs;
|
|
|
|
u->function_addrs_count = function_addrs_count;
|
|
|
|
u->lines = lines;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-19 02:09:47 +01:00
|
|
|
backtrace_atomic_store_size_t (&u->lines_count, count);
|
|
|
|
backtrace_atomic_store_pointer (&u->function_addrs, function_addrs);
|
|
|
|
backtrace_atomic_store_size_t (&u->function_addrs_count,
|
|
|
|
function_addrs_count);
|
|
|
|
backtrace_atomic_store_pointer (&u->lines, lines);
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now all fields of U have been initialized. */
|
|
|
|
|
|
|
|
if (lines == (struct line *) (uintptr_t) -1)
|
|
|
|
{
|
|
|
|
/* If reading the line number information failed in some way,
|
|
|
|
try again to see if there is a better compilation unit for
|
|
|
|
this PC. */
|
|
|
|
if (new_data)
|
2012-10-09 20:20:45 +02:00
|
|
|
return dwarf_lookup_pc (state, ddata, pc, callback, error_callback,
|
|
|
|
data, found);
|
2012-09-17 18:38:38 +02:00
|
|
|
return callback (data, pc, NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for PC within this unit. */
|
|
|
|
|
|
|
|
ln = (struct line *) bsearch (&pc, lines, entry->u->lines_count,
|
|
|
|
sizeof (struct line), line_search);
|
|
|
|
if (ln == NULL)
|
|
|
|
{
|
2013-01-17 02:20:28 +01:00
|
|
|
/* The PC is between the low_pc and high_pc attributes of the
|
|
|
|
compilation unit, but no entry in the line table covers it.
|
|
|
|
This implies that the start of the compilation unit has no
|
|
|
|
line number information. */
|
|
|
|
|
|
|
|
if (entry->u->abs_filename == NULL)
|
|
|
|
{
|
|
|
|
const char *filename;
|
|
|
|
|
|
|
|
filename = entry->u->filename;
|
|
|
|
if (filename != NULL
|
|
|
|
&& !IS_ABSOLUTE_PATH (filename)
|
|
|
|
&& entry->u->comp_dir != NULL)
|
|
|
|
{
|
|
|
|
size_t filename_len;
|
|
|
|
const char *dir;
|
|
|
|
size_t dir_len;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
filename_len = strlen (filename);
|
|
|
|
dir = entry->u->comp_dir;
|
|
|
|
dir_len = strlen (dir);
|
|
|
|
s = (char *) backtrace_alloc (state, dir_len + filename_len + 2,
|
|
|
|
error_callback, data);
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
*found = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memcpy (s, dir, dir_len);
|
|
|
|
/* FIXME: Should use backslash if DOS file system. */
|
|
|
|
s[dir_len] = '/';
|
|
|
|
memcpy (s + dir_len + 1, filename, filename_len + 1);
|
|
|
|
filename = s;
|
|
|
|
}
|
|
|
|
entry->u->abs_filename = filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
return callback (data, pc, entry->u->abs_filename, 0, NULL);
|
2012-09-17 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for function name within this unit. */
|
|
|
|
|
|
|
|
if (entry->u->function_addrs_count == 0)
|
|
|
|
return callback (data, pc, ln->filename, ln->lineno, NULL);
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
p = ((struct function_addrs *)
|
|
|
|
bsearch (&pc, entry->u->function_addrs,
|
|
|
|
entry->u->function_addrs_count,
|
|
|
|
sizeof (struct function_addrs),
|
|
|
|
function_addrs_search));
|
|
|
|
if (p == NULL)
|
2012-09-17 18:38:38 +02:00
|
|
|
return callback (data, pc, ln->filename, ln->lineno, NULL);
|
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
/* Here pc >= p->low && pc < (p + 1)->low. The function_addrs are
|
2020-09-23 02:27:46 +02:00
|
|
|
sorted by low, so if pc > p->low we are at the end of a range of
|
|
|
|
function_addrs with the same low value. If pc == p->low walk
|
|
|
|
forward to the end of the range with that low value. Then walk
|
|
|
|
backward and use the first range that includes pc. */
|
|
|
|
while (pc == (p + 1)->low)
|
|
|
|
++p;
|
2020-09-09 03:18:48 +02:00
|
|
|
fmatch = NULL;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (pc < p->high)
|
|
|
|
{
|
|
|
|
fmatch = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == entry->u->function_addrs)
|
|
|
|
break;
|
|
|
|
if ((p - 1)->low < p->low)
|
|
|
|
break;
|
|
|
|
--p;
|
|
|
|
}
|
|
|
|
if (fmatch == NULL)
|
|
|
|
return callback (data, pc, ln->filename, ln->lineno, NULL);
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2020-09-09 03:18:48 +02:00
|
|
|
function = fmatch->function;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
filename = ln->filename;
|
|
|
|
lineno = ln->lineno;
|
|
|
|
|
|
|
|
ret = report_inlined_functions (pc, function, callback, data,
|
|
|
|
&filename, &lineno);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return callback (data, pc, filename, lineno, function->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-09 20:20:45 +02:00
|
|
|
/* Return the file/line information for a PC using the DWARF mapping
|
|
|
|
we built earlier. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
dwarf_fileline (struct backtrace_state *state, uintptr_t pc,
|
|
|
|
backtrace_full_callback callback,
|
|
|
|
backtrace_error_callback error_callback, void *data)
|
|
|
|
{
|
|
|
|
struct dwarf_data *ddata;
|
|
|
|
int found;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!state->threaded)
|
|
|
|
{
|
|
|
|
for (ddata = (struct dwarf_data *) state->fileline_data;
|
|
|
|
ddata != NULL;
|
|
|
|
ddata = ddata->next)
|
|
|
|
{
|
|
|
|
ret = dwarf_lookup_pc (state, ddata, pc, callback, error_callback,
|
|
|
|
data, &found);
|
|
|
|
if (ret != 0 || found)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct dwarf_data **pp;
|
|
|
|
|
2012-10-10 06:37:06 +02:00
|
|
|
pp = (struct dwarf_data **) (void *) &state->fileline_data;
|
2012-10-09 20:20:45 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2013-11-19 02:09:47 +01:00
|
|
|
ddata = backtrace_atomic_load_pointer (pp);
|
2012-10-09 20:20:45 +02:00
|
|
|
if (ddata == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = dwarf_lookup_pc (state, ddata, pc, callback, error_callback,
|
|
|
|
data, &found);
|
|
|
|
if (ret != 0 || found)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pp = &ddata->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: See if any libraries have been dlopen'ed. */
|
|
|
|
|
|
|
|
return callback (data, pc, NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize our data structures from the DWARF debug info for a
|
|
|
|
file. Return NULL on failure. */
|
|
|
|
|
|
|
|
static struct dwarf_data *
|
|
|
|
build_dwarf_data (struct backtrace_state *state,
|
|
|
|
uintptr_t base_address,
|
2019-12-05 03:20:11 +01:00
|
|
|
const struct dwarf_sections *dwarf_sections,
|
2012-10-09 20:20:45 +02:00
|
|
|
int is_bigendian,
|
2019-01-17 01:07:43 +01:00
|
|
|
struct dwarf_data *altlink,
|
2012-10-09 20:20:45 +02:00
|
|
|
backtrace_error_callback error_callback,
|
|
|
|
void *data)
|
2012-09-17 18:38:38 +02:00
|
|
|
{
|
|
|
|
struct unit_addrs_vector addrs_vec;
|
|
|
|
struct unit_addrs *addrs;
|
|
|
|
size_t addrs_count;
|
2019-01-17 14:42:09 +01:00
|
|
|
struct unit_vector units_vec;
|
|
|
|
struct unit **units;
|
|
|
|
size_t units_count;
|
2012-09-17 18:38:38 +02:00
|
|
|
struct dwarf_data *fdata;
|
|
|
|
|
2019-12-05 03:20:11 +01:00
|
|
|
if (!build_address_map (state, base_address, dwarf_sections, is_bigendian,
|
|
|
|
altlink, error_callback, data, &addrs_vec,
|
|
|
|
&units_vec))
|
2012-10-09 20:20:45 +02:00
|
|
|
return NULL;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
if (!backtrace_vector_release (state, &addrs_vec.vec, error_callback, data))
|
2012-10-09 20:20:45 +02:00
|
|
|
return NULL;
|
2019-01-17 14:42:09 +01:00
|
|
|
if (!backtrace_vector_release (state, &units_vec.vec, error_callback, data))
|
|
|
|
return NULL;
|
2012-09-17 18:38:38 +02:00
|
|
|
addrs = (struct unit_addrs *) addrs_vec.vec.base;
|
2019-01-17 14:42:09 +01:00
|
|
|
units = (struct unit **) units_vec.vec.base;
|
2012-09-17 18:38:38 +02:00
|
|
|
addrs_count = addrs_vec.count;
|
2019-01-17 14:42:09 +01:00
|
|
|
units_count = units_vec.count;
|
2014-03-07 06:07:56 +01:00
|
|
|
backtrace_qsort (addrs, addrs_count, sizeof (struct unit_addrs),
|
|
|
|
unit_addrs_compare);
|
2019-01-17 14:42:09 +01:00
|
|
|
/* No qsort for units required, already sorted. */
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
fdata = ((struct dwarf_data *)
|
|
|
|
backtrace_alloc (state, sizeof (struct dwarf_data),
|
|
|
|
error_callback, data));
|
|
|
|
if (fdata == NULL)
|
2012-10-09 20:20:45 +02:00
|
|
|
return NULL;
|
2012-09-17 18:38:38 +02:00
|
|
|
|
2012-10-09 20:20:45 +02:00
|
|
|
fdata->next = NULL;
|
2019-01-17 01:07:43 +01:00
|
|
|
fdata->altlink = altlink;
|
2012-10-09 20:20:45 +02:00
|
|
|
fdata->base_address = base_address;
|
2012-09-17 18:38:38 +02:00
|
|
|
fdata->addrs = addrs;
|
|
|
|
fdata->addrs_count = addrs_count;
|
2019-01-17 14:42:09 +01:00
|
|
|
fdata->units = units;
|
|
|
|
fdata->units_count = units_count;
|
2019-12-05 03:20:11 +01:00
|
|
|
fdata->dwarf_sections = *dwarf_sections;
|
2012-09-17 18:38:38 +02:00
|
|
|
fdata->is_bigendian = is_bigendian;
|
|
|
|
memset (&fdata->fvec, 0, sizeof fdata->fvec);
|
|
|
|
|
2012-10-09 20:20:45 +02:00
|
|
|
return fdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build our data structures from the DWARF sections for a module.
|
|
|
|
Set FILELINE_FN and STATE->FILELINE_DATA. Return 1 on success, 0
|
|
|
|
on failure. */
|
|
|
|
|
|
|
|
int
|
|
|
|
backtrace_dwarf_add (struct backtrace_state *state,
|
|
|
|
uintptr_t base_address,
|
2019-12-05 03:20:11 +01:00
|
|
|
const struct dwarf_sections *dwarf_sections,
|
2012-10-09 20:20:45 +02:00
|
|
|
int is_bigendian,
|
2019-01-17 01:07:43 +01:00
|
|
|
struct dwarf_data *fileline_altlink,
|
2012-10-09 20:20:45 +02:00
|
|
|
backtrace_error_callback error_callback,
|
2019-01-17 01:07:32 +01:00
|
|
|
void *data, fileline *fileline_fn,
|
|
|
|
struct dwarf_data **fileline_entry)
|
2012-10-09 20:20:45 +02:00
|
|
|
{
|
|
|
|
struct dwarf_data *fdata;
|
|
|
|
|
2019-12-05 03:20:11 +01:00
|
|
|
fdata = build_dwarf_data (state, base_address, dwarf_sections, is_bigendian,
|
2019-01-17 01:07:43 +01:00
|
|
|
fileline_altlink, error_callback, data);
|
2012-10-09 20:20:45 +02:00
|
|
|
if (fdata == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2019-01-17 01:07:32 +01:00
|
|
|
if (fileline_entry != NULL)
|
|
|
|
*fileline_entry = fdata;
|
|
|
|
|
2012-10-09 20:20:45 +02:00
|
|
|
if (!state->threaded)
|
|
|
|
{
|
|
|
|
struct dwarf_data **pp;
|
|
|
|
|
2012-10-10 06:37:06 +02:00
|
|
|
for (pp = (struct dwarf_data **) (void *) &state->fileline_data;
|
2012-10-09 20:20:45 +02:00
|
|
|
*pp != NULL;
|
|
|
|
pp = &(*pp)->next)
|
|
|
|
;
|
|
|
|
*pp = fdata;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
struct dwarf_data **pp;
|
|
|
|
|
2012-10-10 06:37:06 +02:00
|
|
|
pp = (struct dwarf_data **) (void *) &state->fileline_data;
|
2012-10-09 20:20:45 +02:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
struct dwarf_data *p;
|
|
|
|
|
2013-11-19 02:09:47 +01:00
|
|
|
p = backtrace_atomic_load_pointer (pp);
|
2012-10-09 20:20:45 +02:00
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pp = &p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (__sync_bool_compare_and_swap (pp, NULL, fdata))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-09-17 18:38:38 +02:00
|
|
|
|
|
|
|
*fileline_fn = dwarf_fileline;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|