Commit c926fd82 by Ian Lance Taylor Committed by Ian Lance Taylor

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
parent 510873f9
2019-12-13 Ian Lance Taylor <iant@golang.org>
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.
2019-12-08 Ian Lance Taylor <iant@golang.org>
* dwarf.c (struct pcrange): Define.
......
......@@ -385,12 +385,33 @@ BUILDTESTS += ctestg_alloc ctesta_alloc
endif
if HAVE_DWARF5
dwarf5_SOURCES = btest.c testlib.c
dwarf5_CFLAGS = $(AM_CFLAGS) -gdwarf-5
dwarf5_LDADD = libbacktrace.la
BUILDTESTS += dwarf5
dwarf5_alloc_SOURCES = $(dwarf5_SOURCES)
dwarf5_alloc_CFLAGS = $(dwarf5_CFLAGS)
dwarf5_alloc_LDADD = libbacktrace_alloc.la
BUILDTESTS += dwarf5_alloc
endif
endif NATIVE
check_PROGRAMS += $(BUILDTESTS)
TESTS += $(BUILDTESTS)
CLEANFILES = $(TESTS) *.debug elf_for_test.c edtest2_build.c gen_edtest2_build
clean-local:
-rm -rf usr
# We can't use automake's automatic dependency tracking, because it
# breaks when using bootstrap-lean. Automatic dependency tracking
# with GCC bootstrap will cause some of the objects to depend on
......
......@@ -643,6 +643,8 @@ HAVE_COMPRESSED_DEBUG_FALSE
HAVE_COMPRESSED_DEBUG_TRUE
HAVE_ZLIB_FALSE
HAVE_ZLIB_TRUE
HAVE_DWARF5_FALSE
HAVE_DWARF5_TRUE
HAVE_PTHREAD_FALSE
HAVE_PTHREAD_TRUE
PTHREAD_CFLAGS
......@@ -11497,7 +11499,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11500 "configure"
#line 11502 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -11603,7 +11605,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11606 "configure"
#line 11608 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -13280,6 +13282,36 @@ else
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -gdwarf-5 is supported" >&5
$as_echo_n "checking whether -gdwarf-5 is supported... " >&6; }
if ${libbacktrace_cv_lib_dwarf5+:} false; then :
$as_echo_n "(cached) " >&6
else
CFLAGS_hold=$CFLAGS
CFLAGS="$CFLAGS -gdwarf-5"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int i;
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
libbacktrace_cv_lib_dwarf5=yes
else
libbacktrace_cv_lib_dwarf5=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS=$CFLAGS_hold
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libbacktrace_cv_lib_dwarf5" >&5
$as_echo "$libbacktrace_cv_lib_dwarf5" >&6; }
if test "$libbacktrace_cv_lib_dwarf5" = yes; then
HAVE_DWARF5_TRUE=
HAVE_DWARF5_FALSE='#'
else
HAVE_DWARF5_TRUE='#'
HAVE_DWARF5_FALSE=
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compress in -lz" >&5
$as_echo_n "checking for compress in -lz... " >&6; }
if ${ac_cv_lib_z_compress+:} false; then :
......@@ -13665,6 +13697,10 @@ if test -z "${HAVE_PTHREAD_TRUE}" && test -z "${HAVE_PTHREAD_FALSE}"; then
as_fn_error $? "conditional \"HAVE_PTHREAD\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_DWARF5_TRUE}" && test -z "${HAVE_DWARF5_FALSE}"; then
as_fn_error $? "conditional \"HAVE_DWARF5\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_ZLIB_TRUE}" && test -z "${HAVE_ZLIB_FALSE}"; then
as_fn_error $? "conditional \"HAVE_ZLIB\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
......
......@@ -420,6 +420,17 @@ AC_SUBST(PTHREAD_CFLAGS)
AM_CONDITIONAL(HAVE_PTHREAD, test "$libgo_cv_lib_pthread" = yes)
dnl Test whether the compiler supports the -gdwarf-5 option.
AC_CACHE_CHECK([whether -gdwarf-5 is supported],
[libbacktrace_cv_lib_dwarf5],
[CFLAGS_hold=$CFLAGS
CFLAGS="$CFLAGS -gdwarf-5"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([int i;])],
[libbacktrace_cv_lib_dwarf5=yes],
[libbacktrace_cv_lib_dwarf5=no])
CFLAGS=$CFLAGS_hold])
AM_CONDITIONAL(HAVE_DWARF5, test "$libbacktrace_cv_lib_dwarf5" = yes)
AC_CHECK_LIB([z], [compress],
[AC_DEFINE(HAVE_ZLIB, 1, [Define if -lz is available.])])
AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_lib_z_compress" = yes)
......
......@@ -346,6 +346,10 @@ static const char * const dwarf_section_names[DEBUG_MAX] =
".debug_abbrev",
".debug_ranges",
".debug_str",
".debug_addr",
".debug_str_offsets",
".debug_line_str",
".debug_rnglists"
};
/* Information we gather for the sections we care about. */
......
......@@ -295,6 +295,10 @@ enum dwarf_section
DEBUG_ABBREV,
DEBUG_RANGES,
DEBUG_STR,
DEBUG_ADDR,
DEBUG_STR_OFFSETS,
DEBUG_LINE_STR,
DEBUG_RNGLISTS,
DEBUG_MAX
};
......
......@@ -141,7 +141,11 @@ static const char * const debug_section_names[DEBUG_MAX] =
".debug_line",
".debug_abbrev",
".debug_ranges",
".debug_str"
".debug_str",
".debug_addr",
".debug_str_offsets",
".debug_line_str",
".debug_rnglists"
};
/* Information we gather for the sections we care about. */
......
......@@ -1286,6 +1286,8 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
+ (dwsect[i].offset - min_offset));
}
memset (&dwarf_sections, 0, sizeof dwarf_sections);
dwarf_sections.data[DEBUG_INFO] = dwsect[DEBUG_INFO].data;
dwarf_sections.size[DEBUG_INFO] = dwsect[DEBUG_INFO].size;
#if BACKTRACE_XCOFF_SIZE == 32
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment