提交 74d09399 编写于 作者: B bors

Auto merge of #50955 - steveklabnik:update-libbacktrace, r=alexcrichton

Update libbacktrace

We haven't updated libbacktrace in two years. This is just blindly updating to the latest HEAD; I'd like to see what travis says. It at least builds on my machine, running some tests...

This perpetuates the patches from https://github.com/rust-lang/rust/pull/30908
......@@ -53,3 +53,6 @@
[submodule "src/tools/lld"]
path = src/tools/lld
url = https://github.com/rust-lang/lld.git
[submodule "src/libbacktrace"]
path = src/libbacktrace
url = https://github.com/rust-lang-nursery/libbacktrace
......@@ -105,7 +105,7 @@ name = "backtrace"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"backtrace-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -114,11 +114,12 @@ dependencies = [
[[package]]
name = "backtrace-sys"
version = "0.1.16"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -2513,6 +2514,7 @@ dependencies = [
"alloc_jemalloc 0.0.0",
"alloc_system 0.0.0",
"build_helper 0.1.0",
"cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"compiler_builtins 0.0.0",
"core 0.0.0",
"libc 0.0.0",
......@@ -3051,7 +3053,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum assert_cli 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5da59dbd8df54562665b925b427221ceda9b771408cb8a6cbd2125d3b001330b"
"checksum atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "af80143d6f7608d746df1520709e5d141c96f240b0e62b0aa41bdfb53374d9d4"
"checksum backtrace 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ebbe525f66f42d207968308ee86bc2dd60aa5fab535b22e616323a173d097d8e"
"checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
"checksum backtrace-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5fd343a2466c4603f76f38de264bc0526cffc7fa38ba52fb9f13237eccc1ced2"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
......
Subproject commit f4d02bbdbf8a2c5a31f0801dfef597a86caad9e3
2016-05-18 Uros Bizjak <ubizjak@gmail.com>
PR target/71161
* elf.c (phdr_callback) [__i386__]: Add
__attribute__((__force_align_arg_pointer__)).
2016-03-02 Maxim Ostapenko <m.ostapenko@partner.samsung.com>
* elf.c (backtrace_initialize): Properly initialize elf_fileline_fn to
avoid possible crash.
(elf_add): Don't set *fileline_fn to elf_nodebug value in case of
missing debug info anymore.
2016-02-06 John David Anglin <danglin@gcc.gnu.org>
* mmap.c (MAP_FAILED): Define if not defined.
2016-01-04 Jakub Jelinek <jakub@redhat.com>
Update copyright years.
2015-12-18 Andris Pavenis <andris.pavenis@iki.fi>
* configure.ac: Specify that DJGPP do not have mmap
even when sys/mman.h exists.
* configure: Regenerate
2015-12-09 John David Anglin <danglin@gcc.gnu.org>
PR libgfortran/68115
* configure.ac: Set libbacktrace_cv_sys_sync to no on hppa*-*-hpux*.
* configure: Regenerate.
* elf.c (backtrace_initialize): Cast __sync_bool_compare_and_swap call
to void.
2015-09-17 Ian Lance Taylor <iant@google.com>
* posix.c (backtrace_open): Cast second argument of open() to int.
2015-09-11 Ian Lance Taylor <iant@google.com>
* Makefile.am (backtrace.lo): Depend on internal.h.
(sort.lo, stest.lo): Add explicit dependencies.
* Makefile.in: Rebuild.
2015-09-09 Hans-Peter Nilsson <hp@axis.com>
* backtrace.c: #include <sys/types.h>.
2015-09-08 Ian Lance Taylor <iant@google.com>
PR other/67457
* backtrace.c: #include "internal.h".
(struct backtrace_data): Add can_alloc field.
(unwind): If can_alloc is false, don't try to get file/line
information.
(backtrace_full): Set can_alloc field in bdata.
* alloc.c (backtrace_alloc): Don't call error_callback if it is
NULL.
* mmap.c (backtrace_alloc): Likewise.
* internal.h: Update comments for backtrace_alloc and
backtrace_free.
2015-09-08 Ian Lance Taylor <iant@google.com>
PR other/67457
* mmap.c (backtrace_alloc): Correct test for mmap failure.
2015-08-31 Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
* configure.ac: For spu-*-* targets, set have_fcntl to no.
* configure: Regenerate.
2015-08-27 Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
* configure.ac: Remove [disable-shared] argument to LT_INIT.
Remove setting PIC_FLAG when building as target library.
* configure: Regenerate.
2015-08-26 Hans-Peter Nilsson <hp@axis.com>
* configure.ac: Only compile with -fPIC if the target
supports it.
* configure: Regenerate.
2015-08-24 Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
* configure.ac: Set have_mmap to no on spu-*-* targets.
* configure: Regenerate.
2015-08-13 Ian Lance Taylor <iant@google.com>
* dwarf.c (read_function_entry): Add vec_inlined parameter.
Change all callers.
2015-06-11 Martin Sebor <msebor@redhat.com>
PR sanitizer/65479
* dwarf.c (struct line): Add new field idx.
(line_compare): Use it.
(add_line): Set it.
(read_line_info): Reset it.
2015-05-29 Tristan Gingold <gingold@adacore.com>
* pecoff.c: New file.
* Makefile.am (FORMAT_FILES): Add pecoff.c and dependencies.
* Makefile.in: Regenerate.
* filetype.awk: Detect pecoff.
* configure.ac: Define BACKTRACE_SUPPORTS_DATA on elf platforms.
Add pecoff.
* btest.c (test5): Test enabled only if BACKTRACE_SUPPORTS_DATA is
true.
* backtrace-supported.h.in (BACKTRACE_SUPPORTS_DATA): Define.
* configure: Regenerate.
* pecoff.c: New file.
2015-05-13 Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
* Makefile.in: Regenerated with automake-1.11.6.
* aclocal.m4: Likewise.
* configure: Likewise.
2015-01-24 Matthias Klose <doko@ubuntu.com>
* configure.ac: Move AM_ENABLE_MULTILIB before AC_PROG_CC.
* configure: Regenerate.
2015-01-05 Jakub Jelinek <jakub@redhat.com>
Update copyright years.
2014-11-21 H.J. Lu <hongjiu.lu@intel.com>
PR bootstrap/63784
* configure: Regenerated.
2014-11-11 David Malcolm <dmalcolm@redhat.com>
* ChangeLog.jit: New.
2014-11-11 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR target/63610
* configure: Regenerate.
2014-10-23 Ian Lance Taylor <iant@google.com>
* internal.h (backtrace_atomic_load_pointer) [no atomic or sync]:
Fix to return void *.
2014-05-08 Ian Lance Taylor <iant@google.com>
* mmap.c (backtrace_free): If freeing a large aligned block of
memory, call munmap rather than holding onto it.
(backtrace_vector_grow): When growing a vector, double the number
of pages requested. When releasing the old version of a grown
vector, pass the correct size to backtrace_free.
2014-03-07 Ian Lance Taylor <iant@google.com>
* sort.c (backtrace_qsort): Use middle element as pivot.
2014-03-06 Ian Lance Taylor <iant@google.com>
* sort.c: New file.
* stest.c: New file.
* internal.h (backtrace_qsort): Declare.
* dwarf.c (read_abbrevs): Call backtrace_qsort instead of qsort.
(read_line_info, read_function_entry): Likewise.
(read_function_info, build_dwarf_data): Likewise.
* elf.c (elf_initialize_syminfo): Likewise.
* Makefile.am (libbacktrace_la_SOURCES): Add sort.c.
(stest_SOURCES, stest_LDADD): Define.
(check_PROGRAMS): Add stest.
2014-02-07 Misty De Meo <misty@brew.sh>
PR target/58710
* configure.ac: Use AC_LINK_IFELSE in check for
_Unwind_GetIPInfo.
* configure: Regenerate.
2014-01-02 Richard Sandiford <rdsandiford@googlemail.com>
Update copyright years
2013-12-06 Jakub Jelinek <jakub@redhat.com>
* elf.c (ET_DYN): Undefine and define again.
(elf_add): Add exe argument, if true and ehdr.e_type is ET_DYN,
return early -1 without closing the descriptor.
(struct phdr_data): Add exe_descriptor.
(phdr_callback): If pd->exe_descriptor is not -1, for very first
call if dlpi_name is NULL just call elf_add with the exe_descriptor,
otherwise backtrace_close the exe_descriptor if not -1. Adjust
call to elf_add.
(backtrace_initialize): Adjust call to elf_add. If it returns
-1, set pd.exe_descriptor to descriptor, otherwise set it to -1.
2013-12-05 Ian Lance Taylor <iant@google.com>
* alloc.c (backtrace_vector_finish): Add error_callback and data
parameters. Call backtrace_vector_release. Return address base.
* mmap.c (backtrace_vector_finish): Add error_callback and data
parameters. Return address base.
* dwarf.c (read_function_info): Get new address base from
backtrace_vector_finish.
* internal.h (backtrace_vector_finish): Update declaration.
2013-11-27 Ian Lance Taylor <iant@google.com>
* dwarf.c (find_address_ranges): New static function, broken out
of build_address_map.
(build_address_map): Call it.
* btest.c (check): Check for missing filename or function, rather
than crashing.
(f3): Check that enough frames were returned.
2013-11-19 Jakub Jelinek <jakub@redhat.com>
* backtrace.h (backtrace_syminfo_callback): Add symsize argument.
* elf.c (elf_syminfo): Pass 0 or sym->size to the callback as
last argument.
* btest.c (struct symdata): Add size field.
(callback_three): Add symsize argument. Copy it to the data->size
field.
(f23): Set symdata.size to 0.
(test5): Likewise. If sizeof (int) > 1, lookup address of
((uintptr_t) &global) + 1. Verify symdata.val and symdata.size
values.
* atomic.c: Include sys/types.h.
2013-11-18 Ian Lance Taylor <iant@google.com>
* configure.ac: Check for support of __atomic extensions.
* internal.h: Declare or #define atomic functions for use in
backtrace code.
* atomic.c: New file.
* dwarf.c (dwarf_lookup_pc): Use atomic functions.
(dwarf_fileline, backtrace_dwarf_add): Likewise.
* elf.c (elf_add_syminfo_data, elf_syminfo): Likewise.
(backtrace_initialize): Likewise.
* fileline.c (fileline_initialize): Likewise.
* Makefile.am (libbacktrace_la_SOURCES): Add atomic.c.
* configure, config.h.in, Makefile.in: Rebuild.
2013-11-18 Jakub Jelinek <jakub@redhat.com>
* elf.c (SHN_UNDEF): Define.
(elf_initialize_syminfo): Add base_address argument. Ignore symbols
with st_shndx == SHN_UNDEF. Add base_address to address fields.
(elf_add): Adjust caller.
* elf.c (phdr_callback): Process info->dlpi_addr == 0 normally.
2013-11-16 Ian Lance Taylor <iant@google.com>
* backtrace.h (backtrace_create_state): Correct comment about
threading.
2013-11-15 Ian Lance Taylor <iant@google.com>
* backtrace.h (backtrace_syminfo): Update comment and parameter
name to take any address, not just a PC value.
* elf.c (STT_OBJECT): Define.
(elf_nosyms): Rename parameter pc to addr.
(elf_symbol_search): Rename local variable pc to addr.
(elf_initialize_syminfo): Add STT_OBJECT symbols to elf_symbols.
(elf_syminfo): Rename parameter pc to addr.
* btest.c (global): New global variable.
(test5): New test.
(main): Call test5.
2013-10-17 Ian Lance Taylor <iant@google.com>
* elf.c (elf_add): Don't get the wrong offsets if a debug section
is missing.
2013-10-15 David Malcolm <dmalcolm@redhat.com>
* configure.ac: Add --enable-host-shared, setting up
pre-existing PIC_FLAG variable within Makefile.am et al.
* configure: Regenerate.
2013-09-20 Alan Modra <amodra@gmail.com>
* configure: Regenerate.
2013-07-23 Alexander Monakov <amonakov@ispras.ru>
* elf.c (elf_syminfo): Loop over the elf_syminfo_data chain.
2013-07-23 Alexander Monakov <amonakov@ispras.ru>
* elf.c (backtrace_initialize): Pass elf_fileline_fn to
dl_iterate_phdr callbacks.
2013-03-25 Ian Lance Taylor <iant@google.com>
* alloc.c: #include <sys/types.h>.
* mmap.c: Likewise.
2013-01-31 Ian Lance Taylor <iant@google.com>
* dwarf.c (read_function_info): Permit fvec parameter to be NULL.
(dwarf_lookup_pc): Don't use ddata->fvec if threaded.
2013-01-25 Jakub Jelinek <jakub@redhat.com>
PR other/56076
* dwarf.c (read_line_header): Don't crash if DW_AT_comp_dir
attribute was not seen.
2013-01-16 Ian Lance Taylor <iant@google.com>
* dwarf.c (struct unit): Add filename and abs_filename fields.
(build_address_map): Set new fields when reading unit.
(dwarf_lookup_pc): If we don't find an entry in the line table,
just return the main file name.
2013-01-14 Richard Sandiford <rdsandiford@googlemail.com>
Update copyright years.
2013-01-01 Ian Lance Taylor <iant@google.com>
PR bootstrap/54834
* Makefile.am (AM_CPPFLAGS): Remove -I ../gcc/include and -I
$(MULTIBUILDTOP)/../../gcc/include.
* Makefile.in: Rebuild.
2013-01-01 Ian Lance Taylor <iant@google.com>
PR other/55536
* mmap.c (backtrace_alloc): Don't call sync functions if not
threaded.
(backtrace_free): Likewise.
2012-12-12 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* mmapio.c: Define MAP_FAILED if not defined.
2012-12-11 Jakub Jelinek <jakub@redhat.com>
PR bootstrap/54926
* Makefile.am (AM_CFLAGS): Remove -frandom-seed=$@.
* configure.ac: If --with-target-subdir, add -frandom-seed=$@
to EXTRA_FLAGS unconditionally, otherwise check whether the compiler
accepts it.
* Makefile.in: Regenerated.
* configure: Regenerated.
2012-12-07 Jakub Jelinek <jakub@redhat.com>
PR bootstrap/54926
* Makefile.am (AM_CFLAGS): Add -frandom-seed=$@.
* Makefile.in: Regenerated.
2012-11-20 Ian Lance Taylor <iant@google.com>
* dwarf.c (read_attribute): Always clear val.
2012-11-13 Ian Lance Taylor <iant@google.com>
PR other/55312
* configure.ac: Only add -Werror if building a target library.
* configure: Rebuild.
2012-11-12 Ian Lance Taylor <iant@google.com>
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Gerald Pfeifer <gerald@pfeifer.com>
* configure.ac: Check for getexecname.
* fileline.c: #include <errno.h>. Define getexecname if not
available.
(fileline_initialize): Try to find the executable in a few
different ways.
* print.c (error_callback): Only print the filename if it came
from the backtrace state.
* configure, config.h.in: Rebuild.
2012-10-29 Ian Lance Taylor <iant@google.com>
* mmap.c (backtrace_vector_release): Correct last patch: add
aligned, not size.
2012-10-29 Ian Lance Taylor <iant@google.com>
* mmap.c (backtrace_vector_release): Make sure freed block is
aligned on 8-byte boundary.
2012-10-26 Ian Lance Taylor <iant@google.com>
PR other/55087
* posix.c (backtrace_open): Add does_not_exist parameter.
* elf.c (phdr_callback): Do not warn if shared library could not
be opened.
* fileline.c (fileline_initialize): Update calls to
backtrace_open.
* internal.h (backtrace_open): Update declaration.
2012-10-26 Jack Howarth <howarth@bromo.med.uc.edu>
PR target/55061
* configure.ac: Check for _Unwind_GetIPInfo function declaration.
* configure: Regenerate.
2012-10-24 Ian Lance Taylor <iant@google.com>
PR target/55061
* configure.ac: Check whether -funwind-tables option works.
* configure: Rebuild.
2012-10-11 Ian Lance Taylor <iant@google.com>
* configure.ac: Do not use dl_iterate_phdr on Solaris 10.
* configure: Rebuild.
2012-10-10 Ian Lance Taylor <iant@google.com>
* elf.c: Rename all Elf typedefs to start with b_elf, and be all
lower case.
2012-10-10 Hans-Peter Nilsson <hp@bitrange.com>
* elf.c (elf_add_syminfo_data): Add casts to avoid warning.
2012-10-09 Ian Lance Taylor <iant@google.com>
* dwarf.c (dwarf_fileline): Add cast to avoid warning.
(backtrace_dwarf_add): Likewise.
2012-10-09 Ian Lance Taylor <iant@google.com>
Add support for tracing through shared libraries.
* configure.ac: Check for link.h and dl_iterate_phdr.
* elf.c: #include <link.h> if system has dl_iterate_phdr. #undef
ELF macros before #defining them.
(dl_phdr_info, dl_iterate_phdr): Define if system does not have
dl_iterate_phdr.
(struct elf_syminfo_data): Add next field.
(elf_initialize_syminfo): Initialize next field.
(elf_add_syminfo_data): New static function.
(elf_add): New static function, broken out of
backtrace_initialize. Call backtrace_dwarf_add instead of
backtrace_dwarf_initialize.
(struct phdr_data): Define.
(phdr_callback): New static function.
(backtrace_initialize): Call elf_add.
* dwarf.c (struct dwarf_data): Add next and base_address fields.
(add_unit_addr): Add base_address parameter. Change all callers.
(add_unit_ranges, build_address_map): Likewise.
(add_line): Add ddata parameter. Change all callers.
(read_line_program, add_function_range): Likewise.
(dwarf_lookup_pc): New static function, broken out of
dwarf_fileline.
(dwarf_fileline): Call dwarf_lookup_pc.
(build_dwarf_data): New static function.
(backtrace_dwarf_add): New function.
(backtrace_dwarf_initialize): Remove.
* internal.h (backtrace_dwarf_initialize): Don't declare.
(backtrace_dwarf_add): Declare.
* configure, config.h.in: Rebuild.
2012-10-04 Gerald Pfeifer <gerald@pfeifer.com>
* btest.c (f23): Avoid uninitialized variable warning.
2012-10-04 Ian Lance Taylor <iant@google.com>
* dwarf.c: If the system header files do not declare strnlen,
provide our own version.
2012-10-03 Ian Lance Taylor <iant@google.com>
* dwarf.c (read_uleb128): Fix overflow test.
(read_sleb128): Likewise.
(build_address_map): Don't change unit_buf.start.
2012-10-02 Uros Bizjak <ubizjak@gmail.com>
PR other/54761
* configure.ac (EXTRA_FLAGS): New.
* Makefile.am (AM_FLAGS): Add $(EXTRA_FLAGS).
* configure, Makefile.in: Regenerate.
2012-09-29 Ian Lance Taylor <iant@google.com>
PR other/54749
* fileline.c (fileline_initialize): Pass errnum as -1 when
reporting that we could not read executable information after a
previous failure.
2012-09-27 Ian Lance Taylor <iant@google.com>
PR bootstrap/54732
* configure.ac: Add no-dependencies to AM_INIT_AUTOMAKE.
* Makefile.am: Add dependencies for all objects.
* configure, aclocal.m4, Makefile.in: Rebuild.
2012-09-27 Ian Lance Taylor <iant@google.com>
PR other/54726
* elf.c (backtrace_initialize): Set *fileln_fn, not
state->fileln_fn.
2012-09-19 Ian Lance Taylor <iant@google.com>
* configure.ac: Only use GCC_CHECK_UNWIND_GETIPINFO when compiled
as a target library.
* configure: Rebuild.
2012-09-19 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Ian Lance Taylor <iant@google.com>
* configure.ac (GCC_HEADER_STDINT): Invoke.
* backtrace.h: If we can't find <stdint.h>, use "gstdint.h".
* btest.c: Don't include <stdint.h>.
* dwarf.c: Likewise.
* configure, aclocal.m4, Makefile.in, config.h.in: Rebuild.
2012-09-18 Ian Lance Taylor <iant@google.com>
PR bootstrap/54623
* Makefile.am (AM_CPPFLAGS): Define.
(AM_CFLAGS): Remove -I options.
* Makefile.in: Rebuild.
2012-09-18 Ian Lance Taylor <iant@google.com>
* posix.c (O_BINARY): Define if not defined.
(backtrace_open): Pass O_BINARY to open. Only call fcntl if
HAVE_FCNTL is defined.
* configure.ac: Test for the fcntl function.
* configure, config.h.in: Rebuild.
2012-09-18 Ian Lance Taylor <iant@google.com>
* btest.c (test1, test2, test3, test4): Add the unused attribute.
2012-09-18 Ian Lance Taylor <iant@google.com>
* dwarf.c: Correct test of HAVE_DECL_STRNLEN.
2012-09-18 Ian Lance Taylor <iant@google.com>
* configure.ac: Add AC_USE_SYSTEM_EXTENSIONS.
* mmapio.c: Don't define _GNU_SOURCE.
* configure, config.h.in: Rebuild.
2012-09-18 Ian Lance Taylor <iant@google.com>
* configure.ac: Check whether strnlen is declared.
* dwarf.c: Declare strnlen if not declared.
* configure, config.h.in: Rebuild.
2012-09-18 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* fileline.c: Include <stdlib.h>.
* mmap.c: Likewise.
2012-09-17 Ian Lance Taylor <iant@google.com>
PR bootstrap/54611
* nounwind.c (backtrace_full): Rename from backtrace. Add state
parameter.
2012-09-17 Gerald Pfeifer <gerald@pfeifer.com>
PR bootstrap/54611
* nounwind.c (backtrace_simple): Add state parameter.
2012-09-17 Ian Lance Taylor <iant@google.com>
PR bootstrap/54609
* unknown.c (unknown_fileline): Add state parameter, remove
fileline_data parameter, name error_callback parameter.
(backtrace_initialize): Add state parameter.
2012-09-17 Ian Lance Taylor <iant@google.com>
* Initial implementation.
Copyright (C) 2012-2016 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
2014-09-24 David Malcolm <dmalcolm@redhat.com>
* ChangeLog.jit: Add copyright footer.
2013-10-03 David Malcolm <dmalcolm@redhat.com>
* configure.ac: Add --enable-host-shared.
* configure: Regenerate.
Copyright (C) 2013-2014 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
# Makefile.am -- Backtrace Makefile.
# Copyright (C) 2012-2016 Free Software Foundation, Inc.
# 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
# notice, this list of conditions and the following disclaimer.
# (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
# distribution.
# (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.
ACLOCAL_AMFLAGS = -I .. -I ../config
AM_CPPFLAGS = -I $(top_srcdir)/../include -I $(top_srcdir)/../libgcc \
-I ../libgcc
AM_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) $(PIC_FLAG)
noinst_LTLIBRARIES = libbacktrace.la
libbacktrace_la_SOURCES = \
backtrace.h \
atomic.c \
dwarf.c \
fileline.c \
internal.h \
posix.c \
print.c \
sort.c \
state.c
BACKTRACE_FILES = \
backtrace.c \
simple.c \
nounwind.c
FORMAT_FILES = \
elf.c \
pecoff.c \
unknown.c
VIEW_FILES = \
read.c \
mmapio.c
ALLOC_FILES = \
alloc.c \
mmap.c
EXTRA_libbacktrace_la_SOURCES = \
$(BACKTRACE_FILES) \
$(FORMAT_FILES) \
$(VIEW_FILES) \
$(ALLOC_FILES)
libbacktrace_la_LIBADD = \
$(BACKTRACE_FILE) \
$(FORMAT_FILE) \
$(VIEW_FILE) \
$(ALLOC_FILE)
libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
# Testsuite.
check_PROGRAMS =
TESTS = $(check_PROGRAMS)
if NATIVE
btest_SOURCES = btest.c
btest_CFLAGS = $(AM_CFLAGS) -g -O
btest_LDADD = libbacktrace.la
check_PROGRAMS += btest
stest_SOURCES = stest.c
stest_LDADD = libbacktrace.la
check_PROGRAMS += stest
endif NATIVE
# 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
# header files in prev-gcc/include, e.g., stddef.h and stdarg.h. When
# using bootstrap-lean, prev-gcc is removed after each stage. When
# running "make install", those header files will be gone, causing the
# library to be rebuilt at install time. That may not succeed.
# These manual dependencies do not include dependencies on unwind.h,
# even though that is part of GCC, because where to find it depends on
# whether we are being built as a host library or a target library.
INCDIR = $(top_srcdir)/../include
alloc.lo: config.h backtrace.h internal.h
backtrace.lo: config.h backtrace.h internal.h
btest.lo: (INCDIR)/filenames.h backtrace.h backtrace-supported.h
dwarf.lo: config.h $(INCDIR)/dwarf2.h $(INCDIR)/dwarf2.def \
$(INCDIR)/filenames.h backtrace.h internal.h
elf.lo: config.h backtrace.h internal.h
fileline.lo: config.h backtrace.h internal.h
mmap.lo: config.h backtrace.h internal.h
mmapio.lo: config.h backtrace.h internal.h
nounwind.lo: config.h internal.h
pecoff.lo: config.h backtrace.h internal.h
posix.lo: config.h backtrace.h internal.h
print.lo: config.h backtrace.h internal.h
read.lo: config.h backtrace.h internal.h
simple.lo: config.h backtrace.h internal.h
sort.lo: config.h backtrace.h internal.h
stest.lo: config.h backtrace.h internal.h
state.lo: config.h backtrace.h backtrace-supported.h internal.h
unknown.lo: config.h backtrace.h internal.h
此差异已折叠。
The libbacktrace library
Initially written by Ian Lance Taylor <iant@google.com>
The libbacktrace library may be linked into a program or library and
used to produce symbolic backtraces. Sample uses would be to print a
detailed backtrace when an error occurs or to gather detailed
profiling information.
The libbacktrace library is provided under a BSD license. See the
source files for the exact license text.
The public functions are declared and documented in the header file
backtrace.h, which should be #include'd by a user of the library.
Building libbacktrace will generate a file backtrace-supported.h,
which a user of the library may use to determine whether backtraces
will work. See the source file backtrace-supported.h.in for the
macros that it defines.
As of September 2012, libbacktrace only supports ELF executables with
DWARF debugging information. The library is written to make it
straightforward to add support for other object file and debugging
formats.
此差异已折叠。
/* alloc.c -- Memory allocation without mmap.
Copyright (C) 2012-2016 Free Software Foundation, Inc.
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
notice, this list of conditions and the following disclaimer.
(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
distribution.
(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 <sys/types.h>
#include "backtrace.h"
#include "internal.h"
/* Allocation routines to use on systems that do not support anonymous
mmap. This implementation just uses malloc, which means that the
backtrace functions may not be safely invoked from a signal
handler. */
/* Allocate memory like malloc. If ERROR_CALLBACK is NULL, don't
report an error. */
void *
backtrace_alloc (struct backtrace_state *state ATTRIBUTE_UNUSED,
size_t size, backtrace_error_callback error_callback,
void *data)
{
void *ret;
ret = malloc (size);
if (ret == NULL)
{
if (error_callback)
error_callback (data, "malloc", errno);
}
return ret;
}
/* Free memory. */
void
backtrace_free (struct backtrace_state *state ATTRIBUTE_UNUSED,
void *p, size_t size ATTRIBUTE_UNUSED,
backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED)
{
free (p);
}
/* Grow VEC by SIZE bytes. */
void *
backtrace_vector_grow (struct backtrace_state *state ATTRIBUTE_UNUSED,
size_t size, backtrace_error_callback error_callback,
void *data, struct backtrace_vector *vec)
{
void *ret;
if (size > vec->alc)
{
size_t alc;
void *base;
if (vec->size == 0)
alc = 32 * size;
else if (vec->size >= 4096)
alc = vec->size + 4096;
else
alc = 2 * vec->size;
if (alc < vec->size + size)
alc = vec->size + size;
base = realloc (vec->base, alc);
if (base == NULL)
{
error_callback (data, "realloc", errno);
return NULL;
}
vec->base = base;
vec->alc = alc - vec->size;
}
ret = (char *) vec->base + vec->size;
vec->size += size;
vec->alc -= size;
return ret;
}
/* Finish the current allocation on VEC. */
void *
backtrace_vector_finish (struct backtrace_state *state,
struct backtrace_vector *vec,
backtrace_error_callback error_callback,
void *data)
{
void *ret;
/* With this allocator we call realloc in backtrace_vector_grow,
which means we can't easily reuse the memory here. So just
release it. */
if (!backtrace_vector_release (state, vec, error_callback, data))
return NULL;
ret = vec->base;
vec->base = NULL;
vec->size = 0;
vec->alc = 0;
return ret;
}
/* Release any extra space allocated for VEC. */
int
backtrace_vector_release (struct backtrace_state *state ATTRIBUTE_UNUSED,
struct backtrace_vector *vec,
backtrace_error_callback error_callback,
void *data)
{
vec->base = realloc (vec->base, vec->size);
if (vec->base == NULL)
{
error_callback (data, "realloc", errno);
return 0;
}
vec->alc = 0;
return 1;
}
/* ANSI and traditional C compatibility macros
Copyright (C) 1991-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
/* ANSI and traditional C compatibility macros
ANSI C is assumed if __STDC__ is #defined.
Macro ANSI C definition Traditional C definition
----- ---- - ---------- ----------- - ----------
PTR `void *' `char *'
const not defined `'
volatile not defined `'
signed not defined `'
For ease of writing code which uses GCC extensions but needs to be
portable to other compilers, we provide the GCC_VERSION macro that
simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
wrappers around __attribute__. Also, __extension__ will be #defined
to nothing if it doesn't work. See below. */
#ifndef _ANSIDECL_H
#define _ANSIDECL_H 1
#ifdef __cplusplus
extern "C" {
#endif
/* Every source file includes this file,
so they will all get the switch for lint. */
/* LINTLIBRARY */
/* Using MACRO(x,y) in cpp #if conditionals does not work with some
older preprocessors. Thus we can't define something like this:
#define HAVE_GCC_VERSION(MAJOR, MINOR) \
(__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
and then test "#if HAVE_GCC_VERSION(2,7)".
So instead we use the macro below and test it against specific values. */
/* This macro simplifies testing whether we are using gcc, and if it
is of a particular minimum version. (Both major & minor numbers are
significant.) This macro will evaluate to 0 if we are not using
gcc at all. */
#ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
#endif /* GCC_VERSION */
#if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
/* All known AIX compilers implement these things (but don't always
define __STDC__). The RISC/OS MIPS compiler defines these things
in SVR4 mode, but does not define __STDC__. */
/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
C++ compilers, does not define __STDC__, though it acts as if this
was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
#define PTR void *
#undef const
#undef volatile
#undef signed
/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
it too, but it's not in C89. */
#undef inline
#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
/* it's a keyword */
#else
# if GCC_VERSION >= 2007
# define inline __inline__ /* __inline__ prevents -pedantic warnings */
# else
# define inline /* nothing */
# endif
#endif
#else /* Not ANSI C. */
#define PTR char *
/* some systems define these in header files for non-ansi mode */
#undef const
#undef volatile
#undef signed
#undef inline
#define const
#define volatile
#define signed
#define inline
#endif /* ANSI C. */
/* Define macros for some gcc attributes. This permits us to use the
macros freely, and know that they will come into play for the
version of gcc in which they are supported. */
#if (GCC_VERSION < 2007)
# define __attribute__(x)
#endif
/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
#ifndef ATTRIBUTE_MALLOC
# if (GCC_VERSION >= 2096)
# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
# else
# define ATTRIBUTE_MALLOC
# endif /* GNUC >= 2.96 */
#endif /* ATTRIBUTE_MALLOC */
/* Attributes on labels were valid as of gcc 2.93 and g++ 4.5. For
g++ an attribute on a label must be followed by a semicolon. */
#ifndef ATTRIBUTE_UNUSED_LABEL
# ifndef __cplusplus
# if GCC_VERSION >= 2093
# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
# else
# define ATTRIBUTE_UNUSED_LABEL
# endif
# else
# if GCC_VERSION >= 4005
# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED ;
# else
# define ATTRIBUTE_UNUSED_LABEL
# endif
# endif
#endif
/* Similarly to ARG_UNUSED below. Prior to GCC 3.4, the C++ frontend
couldn't parse attributes placed after the identifier name, and now
the entire compiler is built with C++. */
#ifndef ATTRIBUTE_UNUSED
#if GCC_VERSION >= 3004
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#else
#define ATTRIBUTE_UNUSED
#endif
#endif /* ATTRIBUTE_UNUSED */
/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
identifier name. */
#if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
#else /* !__cplusplus || GNUC >= 3.4 */
# define ARG_UNUSED(NAME) NAME
#endif /* !__cplusplus || GNUC >= 3.4 */
#ifndef ATTRIBUTE_NORETURN
#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
#endif /* ATTRIBUTE_NORETURN */
/* Attribute `nonnull' was valid as of gcc 3.3. */
#ifndef ATTRIBUTE_NONNULL
# if (GCC_VERSION >= 3003)
# define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
# else
# define ATTRIBUTE_NONNULL(m)
# endif /* GNUC >= 3.3 */
#endif /* ATTRIBUTE_NONNULL */
/* Attribute `returns_nonnull' was valid as of gcc 4.9. */
#ifndef ATTRIBUTE_RETURNS_NONNULL
# if (GCC_VERSION >= 4009)
# define ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
# else
# define ATTRIBUTE_RETURNS_NONNULL
# endif /* GNUC >= 4.9 */
#endif /* ATTRIBUTE_RETURNS_NONNULL */
/* Attribute `pure' was valid as of gcc 3.0. */
#ifndef ATTRIBUTE_PURE
# if (GCC_VERSION >= 3000)
# define ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
# define ATTRIBUTE_PURE
# endif /* GNUC >= 3.0 */
#endif /* ATTRIBUTE_PURE */
/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
This was the case for the `printf' format attribute by itself
before GCC 3.3, but as of 3.3 we need to add the `nonnull'
attribute to retain this behavior. */
#ifndef ATTRIBUTE_PRINTF
#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
#endif /* ATTRIBUTE_PRINTF */
/* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
a function pointer. Format attributes were allowed on function
pointers as of gcc 3.1. */
#ifndef ATTRIBUTE_FPTR_PRINTF
# if (GCC_VERSION >= 3001)
# define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
# else
# define ATTRIBUTE_FPTR_PRINTF(m, n)
# endif /* GNUC >= 3.1 */
# define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
# define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
# define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
# define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
# define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
#endif /* ATTRIBUTE_FPTR_PRINTF */
/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A
NULL format specifier was allowed as of gcc 3.3. */
#ifndef ATTRIBUTE_NULL_PRINTF
# if (GCC_VERSION >= 3003)
# define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
# else
# define ATTRIBUTE_NULL_PRINTF(m, n)
# endif /* GNUC >= 3.3 */
# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
#endif /* ATTRIBUTE_NULL_PRINTF */
/* Attribute `sentinel' was valid as of gcc 3.5. */
#ifndef ATTRIBUTE_SENTINEL
# if (GCC_VERSION >= 3005)
# define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
# else
# define ATTRIBUTE_SENTINEL
# endif /* GNUC >= 3.5 */
#endif /* ATTRIBUTE_SENTINEL */
#ifndef ATTRIBUTE_ALIGNED_ALIGNOF
# if (GCC_VERSION >= 3000)
# define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
# else
# define ATTRIBUTE_ALIGNED_ALIGNOF(m)
# endif /* GNUC >= 3.0 */
#endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
/* Useful for structures whose layout must much some binary specification
regardless of the alignment and padding qualities of the compiler. */
#ifndef ATTRIBUTE_PACKED
# define ATTRIBUTE_PACKED __attribute__ ((packed))
#endif
/* Attribute `hot' and `cold' was valid as of gcc 4.3. */
#ifndef ATTRIBUTE_COLD
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_COLD __attribute__ ((__cold__))
# else
# define ATTRIBUTE_COLD
# endif /* GNUC >= 4.3 */
#endif /* ATTRIBUTE_COLD */
#ifndef ATTRIBUTE_HOT
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_HOT __attribute__ ((__hot__))
# else
# define ATTRIBUTE_HOT
# endif /* GNUC >= 4.3 */
#endif /* ATTRIBUTE_HOT */
/* Attribute 'no_sanitize_undefined' was valid as of gcc 4.9. */
#ifndef ATTRIBUTE_NO_SANITIZE_UNDEFINED
# if (GCC_VERSION >= 4009)
# define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
# else
# define ATTRIBUTE_NO_SANITIZE_UNDEFINED
# endif /* GNUC >= 4.9 */
#endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */
/* We use __extension__ in some places to suppress -pedantic warnings
about GCC extensions. This feature didn't work properly before
gcc 2.8. */
#if GCC_VERSION < 2008
#define __extension__
#endif
/* This is used to declare a const variable which should be visible
outside of the current compilation unit. Use it as
EXPORTED_CONST int i = 1;
This is because the semantics of const are different in C and C++.
"extern const" is permitted in C but it looks strange, and gcc
warns about it when -Wc++-compat is not used. */
#ifdef __cplusplus
#define EXPORTED_CONST extern const
#else
#define EXPORTED_CONST const
#endif
/* Be conservative and only use enum bitfields with C++ or GCC.
FIXME: provide a complete autoconf test for buggy enum bitfields. */
#ifdef __cplusplus
#define ENUM_BITFIELD(TYPE) enum TYPE
#elif (GCC_VERSION > 2000)
#define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
#else
#define ENUM_BITFIELD(TYPE) unsigned int
#endif
/* This is used to mark a class or virtual function as final. */
#if __cplusplus >= 201103L
#define GCC_FINAL final
#elif GCC_VERSION >= 4007
#define GCC_FINAL __final
#else
#define GCC_FINAL
#endif
#ifdef __cplusplus
}
#endif
#endif /* ansidecl.h */
/* atomic.c -- Support for atomic functions if not present.
Copyright (C) 2013-2016 Free Software Foundation, Inc.
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
notice, this list of conditions and the following disclaimer.
(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
distribution.
(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 <sys/types.h>
#include "backtrace.h"
#include "backtrace-supported.h"
#include "internal.h"
/* This file holds implementations of the atomic functions that are
used if the host compiler has the sync functions but not the atomic
functions, as is true of versions of GCC before 4.7. */
#if !defined (HAVE_ATOMIC_FUNCTIONS) && defined (HAVE_SYNC_FUNCTIONS)
/* Do an atomic load of a pointer. */
void *
backtrace_atomic_load_pointer (void *arg)
{
void **pp;
void *p;
pp = (void **) arg;
p = *pp;
while (!__sync_bool_compare_and_swap (pp, p, p))
p = *pp;
return p;
}
/* Do an atomic load of an int. */
int
backtrace_atomic_load_int (int *p)
{
int i;
i = *p;
while (!__sync_bool_compare_and_swap (p, i, i))
i = *p;
return i;
}
/* Do an atomic store of a pointer. */
void
backtrace_atomic_store_pointer (void *arg, void *p)
{
void **pp;
void *old;
pp = (void **) arg;
old = *pp;
while (!__sync_bool_compare_and_swap (pp, old, p))
old = *pp;
}
/* Do an atomic store of a size_t value. */
void
backtrace_atomic_store_size_t (size_t *p, size_t v)
{
size_t old;
old = *p;
while (!__sync_bool_compare_and_swap (p, old, v))
old = *p;
}
/* Do an atomic store of a int value. */
void
backtrace_atomic_store_int (int *p, int v)
{
size_t old;
old = *p;
while (!__sync_bool_compare_and_swap (p, old, v))
old = *p;
}
#endif
/* backtrace-supported.h.in -- Whether stack backtrace is supported.
Copyright (C) 2012-2016 Free Software Foundation, Inc.
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
notice, this list of conditions and the following disclaimer.
(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
distribution.
(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. */
/* The file backtrace-supported.h.in is used by configure to generate
the file backtrace-supported.h. The file backtrace-supported.h may
be #include'd to see whether the backtrace library will be able to
get a backtrace and produce symbolic information. */
/* BACKTRACE_SUPPORTED will be #define'd as 1 if the backtrace library
should work, 0 if it will not. Libraries may #include this to make
other arrangements. */
#define BACKTRACE_SUPPORTED @BACKTRACE_SUPPORTED@
/* BACKTRACE_USES_MALLOC will be #define'd as 1 if the backtrace
library will call malloc as it works, 0 if it will call mmap
instead. This may be used to determine whether it is safe to call
the backtrace functions from a signal handler. In general this
only applies to calls like backtrace and backtrace_pcinfo. It does
not apply to backtrace_simple, which never calls malloc. It does
not apply to backtrace_print, which always calls fprintf and
therefore malloc. */
#define BACKTRACE_USES_MALLOC @BACKTRACE_USES_MALLOC@
/* BACKTRACE_SUPPORTS_THREADS will be #define'd as 1 if the backtrace
library is configured with threading support, 0 if not. If this is
0, the threaded parameter to backtrace_create_state must be passed
as 0. */
#define BACKTRACE_SUPPORTS_THREADS @BACKTRACE_SUPPORTS_THREADS@
/* BACKTRACE_SUPPORTS_DATA will be #defined'd as 1 if the backtrace_syminfo
will work for variables. It will always work for functions. */
#define BACKTRACE_SUPPORTS_DATA @BACKTRACE_SUPPORTS_DATA@
/* backtrace.c -- Entry point for stack backtrace library.
Copyright (C) 2012-2016 Free Software Foundation, Inc.
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
notice, this list of conditions and the following disclaimer.
(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
distribution.
(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 <sys/types.h>
#include "unwind.h"
#include "backtrace.h"
#include "internal.h"
/* The main backtrace_full routine. */
/* Data passed through _Unwind_Backtrace. */
struct backtrace_data
{
/* Number of frames to skip. */
int skip;
/* Library state. */
struct backtrace_state *state;
/* Callback routine. */
backtrace_full_callback callback;
/* Error callback routine. */
backtrace_error_callback error_callback;
/* Data to pass to callback routines. */
void *data;
/* Value to return from backtrace_full. */
int ret;
/* Whether there is any memory available. */
int can_alloc;
};
/* Unwind library callback routine. This is passed to
_Unwind_Backtrace. */
static _Unwind_Reason_Code
unwind (struct _Unwind_Context *context, void *vdata)
{
struct backtrace_data *bdata = (struct backtrace_data *) vdata;
uintptr_t pc;
int ip_before_insn = 0;
#ifdef HAVE_GETIPINFO
pc = _Unwind_GetIPInfo (context, &ip_before_insn);
#else
pc = _Unwind_GetIP (context);
#endif
if (bdata->skip > 0)
{
--bdata->skip;
return _URC_NO_REASON;
}
if (!ip_before_insn)
--pc;
if (!bdata->can_alloc)
bdata->ret = bdata->callback (bdata->data, pc, NULL, 0, NULL);
else
bdata->ret = backtrace_pcinfo (bdata->state, pc, bdata->callback,
bdata->error_callback, bdata->data);
if (bdata->ret != 0)
return _URC_END_OF_STACK;
return _URC_NO_REASON;
}
/* Get a stack backtrace. */
int
backtrace_full (struct backtrace_state *state, int skip,
backtrace_full_callback callback,
backtrace_error_callback error_callback, void *data)
{
struct backtrace_data bdata;
void *p;
bdata.skip = skip + 1;
bdata.state = state;
bdata.callback = callback;
bdata.error_callback = error_callback;
bdata.data = data;
bdata.ret = 0;
/* If we can't allocate any memory at all, don't try to produce
file/line information. */
p = backtrace_alloc (state, 4096, NULL, NULL);
if (p == NULL)
bdata.can_alloc = 0;
else
{
backtrace_free (state, p, 4096, NULL, NULL);
bdata.can_alloc = 1;
}
_Unwind_Backtrace (unwind, &bdata);
return bdata.ret;
}
/* backtrace.h -- Public header file for stack backtrace library.
Copyright (C) 2012-2016 Free Software Foundation, Inc.
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
notice, this list of conditions and the following disclaimer.
(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
distribution.
(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. */
#ifndef BACKTRACE_H
#define BACKTRACE_H
#include <stddef.h>
#include <stdio.h>
/* We want to get a definition for uintptr_t, but we still care about
systems that don't have <stdint.h>. */
#if defined(__GLIBC__) && __GLIBC__ >= 2
#include <stdint.h>
#elif defined(HAVE_STDINT_H)
#include <stdint.h>
#else
/* Systems that don't have <stdint.h> must provide gstdint.h, e.g.,
from GCC_HEADER_STDINT in configure.ac. */
#include "gstdint.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* The backtrace state. This struct is intentionally not defined in
the public interface. */
struct backtrace_state;
/* The type of the error callback argument to backtrace functions.
This function, if not NULL, will be called for certain error cases.
The DATA argument is passed to the function that calls this one.
The MSG argument is an error message. The ERRNUM argument, if
greater than 0, holds an errno value. The MSG buffer may become
invalid after this function returns.
As a special case, the ERRNUM argument will be passed as -1 if no
debug info can be found for the executable, but the function
requires debug info (e.g., backtrace_full, backtrace_pcinfo). The
MSG in this case will be something along the lines of "no debug
info". Similarly, ERRNUM will be passed as -1 if there is no
symbol table, but the function requires a symbol table (e.g.,
backtrace_syminfo). This may be used as a signal that some other
approach should be tried. */
typedef void (*backtrace_error_callback) (void *data, const char *msg,
int errnum);
/* Create state information for the backtrace routines. This must be
called before any of the other routines, and its return value must
be passed to all of the other routines. FILENAME is the path name
of the executable file; if it is NULL the library will try
system-specific path names. If not NULL, FILENAME must point to a
permanent buffer. If THREADED is non-zero the state may be
accessed by multiple threads simultaneously, and the library will
use appropriate atomic operations. If THREADED is zero the state
may only be accessed by one thread at a time. This returns a state
pointer on success, NULL on error. If an error occurs, this will
call the ERROR_CALLBACK routine. */
extern struct backtrace_state *backtrace_create_state (
const char *filename, int threaded,
backtrace_error_callback error_callback, void *data);
/* The type of the callback argument to the backtrace_full function.
DATA is the argument passed to backtrace_full. PC is the program
counter. FILENAME is the name of the file containing PC, or NULL
if not available. LINENO is the line number in FILENAME containing
PC, or 0 if not available. FUNCTION is the name of the function
containing PC, or NULL if not available. This should return 0 to
continuing tracing. The FILENAME and FUNCTION buffers may become
invalid after this function returns. */
typedef int (*backtrace_full_callback) (void *data, uintptr_t pc,
const char *filename, int lineno,
const char *function);
/* Get a full stack backtrace. SKIP is the number of frames to skip;
passing 0 will start the trace with the function calling
backtrace_full. DATA is passed to the callback routine. If any
call to CALLBACK returns a non-zero value, the stack backtrace
stops, and backtrace returns that value; this may be used to limit
the number of stack frames desired. If all calls to CALLBACK
return 0, backtrace returns 0. The backtrace_full function will
make at least one call to either CALLBACK or ERROR_CALLBACK. This
function requires debug info for the executable. */
extern int backtrace_full (struct backtrace_state *state, int skip,
backtrace_full_callback callback,
backtrace_error_callback error_callback,
void *data);
/* The type of the callback argument to the backtrace_simple function.
DATA is the argument passed to simple_backtrace. PC is the program
counter. This should return 0 to continue tracing. */
typedef int (*backtrace_simple_callback) (void *data, uintptr_t pc);
/* Get a simple backtrace. SKIP is the number of frames to skip, as
in backtrace. DATA is passed to the callback routine. If any call
to CALLBACK returns a non-zero value, the stack backtrace stops,
and backtrace_simple returns that value. Otherwise
backtrace_simple returns 0. The backtrace_simple function will
make at least one call to either CALLBACK or ERROR_CALLBACK. This
function does not require any debug info for the executable. */
extern int backtrace_simple (struct backtrace_state *state, int skip,
backtrace_simple_callback callback,
backtrace_error_callback error_callback,
void *data);
/* Print the current backtrace in a user readable format to a FILE.
SKIP is the number of frames to skip, as in backtrace_full. Any
error messages are printed to stderr. This function requires debug
info for the executable. */
extern void backtrace_print (struct backtrace_state *state, int skip, FILE *);
/* Given PC, a program counter in the current program, call the
callback function with filename, line number, and function name
information. This will normally call the callback function exactly
once. However, if the PC happens to describe an inlined call, and
the debugging information contains the necessary information, then
this may call the callback function multiple times. This will make
at least one call to either CALLBACK or ERROR_CALLBACK. This
returns the first non-zero value returned by CALLBACK, or 0. */
extern int backtrace_pcinfo (struct backtrace_state *state, uintptr_t pc,
backtrace_full_callback callback,
backtrace_error_callback error_callback,
void *data);
/* The type of the callback argument to backtrace_syminfo. DATA and
PC are the arguments passed to backtrace_syminfo. SYMNAME is the
name of the symbol for the corresponding code. SYMVAL is the
value and SYMSIZE is the size of the symbol. SYMNAME will be NULL
if no error occurred but the symbol could not be found. */
typedef void (*backtrace_syminfo_callback) (void *data, uintptr_t pc,
const char *symname,
uintptr_t symval,
uintptr_t symsize);
/* Given ADDR, an address or program counter in the current program,
call the callback information with the symbol name and value
describing the function or variable in which ADDR may be found.
This will call either CALLBACK or ERROR_CALLBACK exactly once.
This returns 1 on success, 0 on failure. This function requires
the symbol table but does not require the debug info. Note that if
the symbol table is present but ADDR could not be found in the
table, CALLBACK will be called with a NULL SYMNAME argument.
Returns 1 on success, 0 on error. */
extern int backtrace_syminfo (struct backtrace_state *state, uintptr_t addr,
backtrace_syminfo_callback callback,
backtrace_error_callback error_callback,
void *data);
#ifdef __cplusplus
} /* End extern "C". */
#endif
#endif
/* btest.c -- Test for libbacktrace library
Copyright (C) 2012-2016 Free Software Foundation, Inc.
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
notice, this list of conditions and the following disclaimer.
(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
distribution.
(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. */
/* This program tests the externally visible interfaces of the
libbacktrace library. */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "filenames.h"
#include "backtrace.h"
#include "backtrace-supported.h"
/* Portable attribute syntax. Actually some of these tests probably
won't work if the attributes are not recognized. */
#ifndef GCC_VERSION
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
#endif
#if (GCC_VERSION < 2007)
# define __attribute__(x)
#endif
#ifndef ATTRIBUTE_UNUSED
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
/* Used to collect backtrace info. */
struct info
{
char *filename;
int lineno;
char *function;
};
/* Passed to backtrace callback function. */
struct bdata
{
struct info *all;
size_t index;
size_t max;
int failed;
};
/* Passed to backtrace_simple callback function. */
struct sdata
{
uintptr_t *addrs;
size_t index;
size_t max;
int failed;
};
/* Passed to backtrace_syminfo callback function. */
struct symdata
{
const char *name;
uintptr_t val, size;
int failed;
};
/* The backtrace state. */
static void *state;
/* The number of failures. */
static int failures;
/* Return the base name in a path. */
static const char *
base (const char *p)
{
const char *last;
const char *s;
last = NULL;
for (s = p; *s != '\0'; ++s)
{
if (IS_DIR_SEPARATOR (*s))
last = s + 1;
}
return last != NULL ? last : p;
}
/* Check an entry in a struct info array. */
static void
check (const char *name, int index, const struct info *all, int want_lineno,
const char *want_function, int *failed)
{
if (*failed)
return;
if (all[index].filename == NULL || all[index].function == NULL)
{
fprintf (stderr, "%s: [%d]: missing file name or function name\n",
name, index);
*failed = 1;
return;
}
if (strcmp (base (all[index].filename), "btest.c") != 0)
{
fprintf (stderr, "%s: [%d]: got %s expected test.c\n", name, index,
all[index].filename);
*failed = 1;
}
if (all[index].lineno != want_lineno)
{
fprintf (stderr, "%s: [%d]: got %d expected %d\n", name, index,
all[index].lineno, want_lineno);
*failed = 1;
}
if (strcmp (all[index].function, want_function) != 0)
{
fprintf (stderr, "%s: [%d]: got %s expected %s\n", name, index,
all[index].function, want_function);
*failed = 1;
}
}
/* The backtrace callback function. */
static int
callback_one (void *vdata, uintptr_t pc ATTRIBUTE_UNUSED,
const char *filename, int lineno, const char *function)
{
struct bdata *data = (struct bdata *) vdata;
struct info *p;
if (data->index >= data->max)
{
fprintf (stderr, "callback_one: callback called too many times\n");
data->failed = 1;
return 1;
}
p = &data->all[data->index];
if (filename == NULL)
p->filename = NULL;
else
{
p->filename = strdup (filename);
assert (p->filename != NULL);
}
p->lineno = lineno;
if (function == NULL)
p->function = NULL;
else
{
p->function = strdup (function);
assert (p->function != NULL);
}
++data->index;
return 0;
}
/* An error callback passed to backtrace. */
static void
error_callback_one (void *vdata, const char *msg, int errnum)
{
struct bdata *data = (struct bdata *) vdata;
fprintf (stderr, "%s", msg);
if (errnum > 0)
fprintf (stderr, ": %s", strerror (errnum));
fprintf (stderr, "\n");
data->failed = 1;
}
/* The backtrace_simple callback function. */
static int
callback_two (void *vdata, uintptr_t pc)
{
struct sdata *data = (struct sdata *) vdata;
if (data->index >= data->max)
{
fprintf (stderr, "callback_two: callback called too many times\n");
data->failed = 1;
return 1;
}
data->addrs[data->index] = pc;
++data->index;
return 0;
}
/* An error callback passed to backtrace_simple. */
static void
error_callback_two (void *vdata, const char *msg, int errnum)
{
struct sdata *data = (struct sdata *) vdata;
fprintf (stderr, "%s", msg);
if (errnum > 0)
fprintf (stderr, ": %s", strerror (errnum));
fprintf (stderr, "\n");
data->failed = 1;
}
/* The backtrace_syminfo callback function. */
static void
callback_three (void *vdata, uintptr_t pc ATTRIBUTE_UNUSED,
const char *symname, uintptr_t symval,
uintptr_t symsize)
{
struct symdata *data = (struct symdata *) vdata;
if (symname == NULL)
data->name = NULL;
else
{
data->name = strdup (symname);
assert (data->name != NULL);
}
data->val = symval;
data->size = symsize;
}
/* The backtrace_syminfo error callback function. */
static void
error_callback_three (void *vdata, const char *msg, int errnum)
{
struct symdata *data = (struct symdata *) vdata;
fprintf (stderr, "%s", msg);
if (errnum > 0)
fprintf (stderr, ": %s", strerror (errnum));
fprintf (stderr, "\n");
data->failed = 1;
}
/* Test the backtrace function with non-inlined functions. */
static int test1 (void) __attribute__ ((noinline, unused));
static int f2 (int) __attribute__ ((noinline));
static int f3 (int, int) __attribute__ ((noinline));
static int
test1 (void)
{
/* Returning a value here and elsewhere avoids a tailcall which
would mess up the backtrace. */
return f2 (__LINE__) + 1;
}
static int
f2 (int f1line)
{
return f3 (f1line, __LINE__) + 2;
}
static int
f3 (int f1line, int f2line)
{
struct info all[20];
struct bdata data;
int f3line;
int i;
data.all = &all[0];
data.index = 0;
data.max = 20;
data.failed = 0;
f3line = __LINE__ + 1;
i = backtrace_full (state, 0, callback_one, error_callback_one, &data);
if (i != 0)
{
fprintf (stderr, "test1: unexpected return value %d\n", i);
data.failed = 1;
}
if (data.index < 3)
{
fprintf (stderr,
"test1: not enough frames; got %zu, expected at least 3\n",
data.index);
data.failed = 1;
}
check ("test1", 0, all, f3line, "f3", &data.failed);
check ("test1", 1, all, f2line, "f2", &data.failed);
check ("test1", 2, all, f1line, "test1", &data.failed);
printf ("%s: backtrace_full noinline\n", data.failed ? "FAIL" : "PASS");
if (data.failed)
++failures;
return failures;
}
/* Test the backtrace function with inlined functions. */
static inline int test2 (void) __attribute__ ((always_inline, unused));
static inline int f12 (int) __attribute__ ((always_inline));
static inline int f13 (int, int) __attribute__ ((always_inline));
static inline int
test2 (void)
{
return f12 (__LINE__) + 1;
}
static inline int
f12 (int f1line)
{
return f13 (f1line, __LINE__) + 2;
}
static inline int
f13 (int f1line, int f2line)
{
struct info all[20];
struct bdata data;
int f3line;
int i;
data.all = &all[0];
data.index = 0;
data.max = 20;
data.failed = 0;
f3line = __LINE__ + 1;
i = backtrace_full (state, 0, callback_one, error_callback_one, &data);
if (i != 0)
{
fprintf (stderr, "test2: unexpected return value %d\n", i);
data.failed = 1;
}
check ("test2", 0, all, f3line, "f13", &data.failed);
check ("test2", 1, all, f2line, "f12", &data.failed);
check ("test2", 2, all, f1line, "test2", &data.failed);
printf ("%s: backtrace_full inline\n", data.failed ? "FAIL" : "PASS");
if (data.failed)
++failures;
return failures;
}
/* Test the backtrace_simple function with non-inlined functions. */
static int test3 (void) __attribute__ ((noinline, unused));
static int f22 (int) __attribute__ ((noinline));
static int f23 (int, int) __attribute__ ((noinline));
static int
test3 (void)
{
return f22 (__LINE__) + 1;
}
static int
f22 (int f1line)
{
return f23 (f1line, __LINE__) + 2;
}
static int
f23 (int f1line, int f2line)
{
uintptr_t addrs[20];
struct sdata data;
int f3line;
int i;
data.addrs = &addrs[0];
data.index = 0;
data.max = 20;
data.failed = 0;
f3line = __LINE__ + 1;
i = backtrace_simple (state, 0, callback_two, error_callback_two, &data);
if (i != 0)
{
fprintf (stderr, "test3: unexpected return value %d\n", i);
data.failed = 1;
}
if (!data.failed)
{
struct info all[20];
struct bdata bdata;
int j;
bdata.all = &all[0];
bdata.index = 0;
bdata.max = 20;
bdata.failed = 0;
for (j = 0; j < 3; ++j)
{
i = backtrace_pcinfo (state, addrs[j], callback_one,
error_callback_one, &bdata);
if (i != 0)
{
fprintf (stderr,
("test3: unexpected return value "
"from backtrace_pcinfo %d\n"),
i);
bdata.failed = 1;
}
if (!bdata.failed && bdata.index != (size_t) (j + 1))
{
fprintf (stderr,
("wrong number of calls from backtrace_pcinfo "
"got %u expected %d\n"),
(unsigned int) bdata.index, j + 1);
bdata.failed = 1;
}
}
check ("test3", 0, all, f3line, "f23", &bdata.failed);
check ("test3", 1, all, f2line, "f22", &bdata.failed);
check ("test3", 2, all, f1line, "test3", &bdata.failed);
if (bdata.failed)
data.failed = 1;
for (j = 0; j < 3; ++j)
{
struct symdata symdata;
symdata.name = NULL;
symdata.val = 0;
symdata.size = 0;
symdata.failed = 0;
i = backtrace_syminfo (state, addrs[j], callback_three,
error_callback_three, &symdata);
if (i == 0)
{
fprintf (stderr,
("test3: [%d]: unexpected return value "
"from backtrace_syminfo %d\n"),
j, i);
symdata.failed = 1;
}
if (!symdata.failed)
{
const char *expected;
switch (j)
{
case 0:
expected = "f23";
break;
case 1:
expected = "f22";
break;
case 2:
expected = "test3";
break;
default:
assert (0);
}
if (symdata.name == NULL)
{
fprintf (stderr, "test3: [%d]: NULL syminfo name\n", j);
symdata.failed = 1;
}
/* Use strncmp, not strcmp, because GCC might create a
clone. */
else if (strncmp (symdata.name, expected, strlen (expected))
!= 0)
{
fprintf (stderr,
("test3: [%d]: unexpected syminfo name "
"got %s expected %s\n"),
j, symdata.name, expected);
symdata.failed = 1;
}
}
if (symdata.failed)
data.failed = 1;
}
}
printf ("%s: backtrace_simple noinline\n", data.failed ? "FAIL" : "PASS");
if (data.failed)
++failures;
return failures;
}
/* Test the backtrace_simple function with inlined functions. */
static inline int test4 (void) __attribute__ ((always_inline, unused));
static inline int f32 (int) __attribute__ ((always_inline));
static inline int f33 (int, int) __attribute__ ((always_inline));
static inline int
test4 (void)
{
return f32 (__LINE__) + 1;
}
static inline int
f32 (int f1line)
{
return f33 (f1line, __LINE__) + 2;
}
static inline int
f33 (int f1line, int f2line)
{
uintptr_t addrs[20];
struct sdata data;
int f3line;
int i;
data.addrs = &addrs[0];
data.index = 0;
data.max = 20;
data.failed = 0;
f3line = __LINE__ + 1;
i = backtrace_simple (state, 0, callback_two, error_callback_two, &data);
if (i != 0)
{
fprintf (stderr, "test3: unexpected return value %d\n", i);
data.failed = 1;
}
if (!data.failed)
{
struct info all[20];
struct bdata bdata;
bdata.all = &all[0];
bdata.index = 0;
bdata.max = 20;
bdata.failed = 0;
i = backtrace_pcinfo (state, addrs[0], callback_one, error_callback_one,
&bdata);
if (i != 0)
{
fprintf (stderr,
("test4: unexpected return value "
"from backtrace_pcinfo %d\n"),
i);
bdata.failed = 1;
}
check ("test4", 0, all, f3line, "f33", &bdata.failed);
check ("test4", 1, all, f2line, "f32", &bdata.failed);
check ("test4", 2, all, f1line, "test4", &bdata.failed);
if (bdata.failed)
data.failed = 1;
}
printf ("%s: backtrace_simple inline\n", data.failed ? "FAIL" : "PASS");
if (data.failed)
++failures;
return failures;
}
#if BACKTRACE_SUPPORTS_DATA
int global = 1;
static int
test5 (void)
{
struct symdata symdata;
int i;
uintptr_t addr = (uintptr_t) &global;
if (sizeof (global) > 1)
addr += 1;
symdata.name = NULL;
symdata.val = 0;
symdata.size = 0;
symdata.failed = 0;
i = backtrace_syminfo (state, addr, callback_three,
error_callback_three, &symdata);
if (i == 0)
{
fprintf (stderr,
"test5: unexpected return value from backtrace_syminfo %d\n",
i);
symdata.failed = 1;
}
if (!symdata.failed)
{
if (symdata.name == NULL)
{
fprintf (stderr, "test5: NULL syminfo name\n");
symdata.failed = 1;
}
else if (strcmp (symdata.name, "global") != 0)
{
fprintf (stderr,
"test5: unexpected syminfo name got %s expected %s\n",
symdata.name, "global");
symdata.failed = 1;
}
else if (symdata.val != (uintptr_t) &global)
{
fprintf (stderr,
"test5: unexpected syminfo value got %lx expected %lx\n",
(unsigned long) symdata.val,
(unsigned long) (uintptr_t) &global);
symdata.failed = 1;
}
else if (symdata.size != sizeof (global))
{
fprintf (stderr,
"test5: unexpected syminfo size got %lx expected %lx\n",
(unsigned long) symdata.size,
(unsigned long) sizeof (global));
symdata.failed = 1;
}
}
printf ("%s: backtrace_syminfo variable\n",
symdata.failed ? "FAIL" : "PASS");
if (symdata.failed)
++failures;
return failures;
}
#endif /* BACKTRACE_SUPPORTS_DATA */
static void
error_callback_create (void *data ATTRIBUTE_UNUSED, const char *msg,
int errnum)
{
fprintf (stderr, "%s", msg);
if (errnum > 0)
fprintf (stderr, ": %s", strerror (errnum));
fprintf (stderr, "\n");
exit (EXIT_FAILURE);
}
/* Run all the tests. */
int
main (int argc ATTRIBUTE_UNUSED, char **argv)
{
state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
error_callback_create, NULL);
#if BACKTRACE_SUPPORTED
test1 ();
test2 ();
test3 ();
test4 ();
#if BACKTRACE_SUPPORTS_DATA
test5 ();
#endif
#endif
exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
}
/* config.h.in. Generated from configure.ac by autoheader. */
/* ELF size: 32 or 64 */
#undef BACKTRACE_ELF_SIZE
/* Define to 1 if you have the __atomic functions */
#undef HAVE_ATOMIC_FUNCTIONS
/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
don't. */
#undef HAVE_DECL_STRNLEN
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define if dl_iterate_phdr is available. */
#undef HAVE_DL_ITERATE_PHDR
/* Define to 1 if you have the fcntl function */
#undef HAVE_FCNTL
/* Define if getexecname is available. */
#undef HAVE_GETEXECNAME
/* Define if _Unwind_GetIPInfo is available. */
#undef HAVE_GETIPINFO
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <link.h> header file. */
#undef HAVE_LINK_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the __sync functions */
#undef HAVE_SYNC_FUNCTIONS
/* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `char', as computed by sizeof. */
#undef SIZEOF_CHAR
/* The size of `int', as computed by sizeof. */
#undef SIZEOF_INT
/* The size of `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* The size of `void *', as computed by sizeof. */
#undef SIZEOF_VOID_P
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Enable extensions on AIX 3, Interix. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
#endif
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Enable threading extensions on Solaris. */
#ifndef _POSIX_PTHREAD_SEMANTICS
# undef _POSIX_PTHREAD_SEMANTICS
#endif
/* Enable extensions on HP NonStop. */
#ifndef _TANDEM_SOURCE
# undef _TANDEM_SOURCE
#endif
/* Enable general extensions on Solaris. */
#ifndef __EXTENSIONS__
# undef __EXTENSIONS__
#endif
/* Define to 1 if on MINIX. */
#undef _MINIX
/* Define to 2 if the system does not provide POSIX.1 features except with
this defined. */
#undef _POSIX_1_SOURCE
/* Define to 1 if you need to in order for `stat' and other things to work. */
#undef _POSIX_SOURCE
此差异已折叠。
此差异已折叠。
# configure.ac -- Backtrace configure script.
# Copyright (C) 2012-2016 Free Software Foundation, Inc.
# 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
# notice, this list of conditions and the following disclaimer.
# (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
# distribution.
# (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.
AC_PREREQ(2.64)
AC_INIT(package-unused, version-unused,, libbacktrace)
AC_CONFIG_SRCDIR(backtrace.h)
AC_CONFIG_HEADER(config.h)
if test -n "${with_target_subdir}"; then
AM_ENABLE_MULTILIB(, ..)
fi
AC_CANONICAL_SYSTEM
target_alias=${target_alias-$host_alias}
AC_USE_SYSTEM_EXTENSIONS
libtool_VERSION=1:0:0
AC_SUBST(libtool_VERSION)
# 1.11.1: Require that version of automake.
# foreign: Don't require README, INSTALL, NEWS, etc.
# no-define: Don't define PACKAGE and VERSION.
# no-dependencies: Don't generate automatic dependencies.
# (because it breaks when using bootstrap-lean, since some of the
# headers are gone at "make install" time).
# -Wall: Issue all automake warnings.
# -Wno-portability: Don't warn about constructs supported by GNU make.
# (because GCC requires GNU make anyhow).
AM_INIT_AUTOMAKE([1.11.1 foreign no-dist no-define no-dependencies -Wall -Wno-portability])
AM_MAINTAINER_MODE
AC_ARG_WITH(target-subdir,
[ --with-target-subdir=SUBDIR Configuring in a subdirectory for target])
# We must force CC to /not/ be precious variables; otherwise
# the wrong, non-multilib-adjusted value will be used in multilibs.
# As a side effect, we have to subst CFLAGS ourselves.
m4_rename([_AC_ARG_VAR_PRECIOUS],[backtrace_PRECIOUS])
m4_define([_AC_ARG_VAR_PRECIOUS],[])
AC_PROG_CC
m4_rename_force([backtrace_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
AC_SUBST(CFLAGS)
AC_PROG_RANLIB
AC_PROG_AWK
case "$AWK" in
"") AC_MSG_ERROR([can't build without awk]) ;;
esac
LT_INIT
AM_PROG_LIBTOOL
backtrace_supported=yes
if test -n "${with_target_subdir}"; then
# We are compiling a GCC library. We can assume that the unwind
# library exists.
BACKTRACE_FILE="backtrace.lo simple.lo"
else
AC_CHECK_HEADER([unwind.h],
[AC_CHECK_FUNC([_Unwind_Backtrace],
[BACKTRACE_FILE="backtrace.lo simple.lo"],
[BACKTRACE_FILE="nounwind.lo"
backtrace_supported=no])],
[BACKTRACE_FILE="nounwind.lo"
backtrace_supported=no])
fi
AC_SUBST(BACKTRACE_FILE)
EXTRA_FLAGS=
if test -n "${with_target_subdir}"; then
EXTRA_FLAGS="-funwind-tables -frandom-seed=\$@"
else
AC_CACHE_CHECK([for -funwind-tables option],
[libbacktrace_cv_c_unwind_tables],
[CFLAGS_hold="$CFLAGS"
CFLAGS="$CFLAGS -funwind-tables"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([static int f() { return 0; }], [return f();])],
[libbacktrace_cv_c_unwind_tables=yes],
[libbacktrace_cv_c_unwind_tables=no])
CFLAGS="$CFLAGS_hold"])
if test "$libbacktrace_cv_c_unwind_tables" = "yes"; then
EXTRA_FLAGS=-funwind-tables
fi
AC_CACHE_CHECK([for -frandom-seed=string option],
[libbacktrace_cv_c_random_seed_string],
[CFLAGS_hold="$CFLAGS"
CFLAGS="$CFLAGS -frandom-seed=conftest.lo"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([], [return 0;])],
[libbacktrace_cv_c_random_seed_string=yes],
[libbacktrace_cv_c_random_seed_string=no])
CFLAGS="$CFLAGS_hold"])
if test "$libbacktrace_cv_c_random_seed_string" = "yes"; then
EXTRA_FLAGS="$EXTRA_FLAGS -frandom-seed=\$@"
fi
fi
AC_SUBST(EXTRA_FLAGS)
ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
-Wmissing-prototypes -Wold-style-definition \
-Wmissing-format-attribute -Wcast-qual],
[WARN_FLAGS])
if test -n "${with_target_subdir}"; then
WARN_FLAGS="$WARN_FLAGS -Werror"
fi
AC_SUBST(WARN_FLAGS)
if test -n "${with_target_subdir}"; then
GCC_CHECK_UNWIND_GETIPINFO
else
ac_save_CFFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
AC_MSG_CHECKING([for _Unwind_GetIPInfo])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[#include "unwind.h"
struct _Unwind_Context *context;
int ip_before_insn = 0;],
[return _Unwind_GetIPInfo (context, &ip_before_insn);])],
[have_unwind_getipinfo=yes], [have_unwind_getipinfo=no])
CFLAGS="$ac_save_CFLAGS"
AC_MSG_RESULT([$have_unwind_getipinfo])
if test "$have_unwind_getipinfo" = "yes"; then
AC_DEFINE(HAVE_GETIPINFO, 1, [Define if _Unwind_GetIPInfo is available.])
fi
fi
# Enable --enable-host-shared.
AC_ARG_ENABLE(host-shared,
[AS_HELP_STRING([--enable-host-shared],
[build host code as shared libraries])],
[PIC_FLAG=-fPIC], [PIC_FLAG=])
AC_SUBST(PIC_FLAG)
# Test for __sync support.
AC_CACHE_CHECK([__sync extensions],
[libbacktrace_cv_sys_sync],
[if test -n "${with_target_subdir}"; then
case "${host}" in
hppa*-*-hpux*) libbacktrace_cv_sys_sync=no ;;
*) libbacktrace_cv_sys_sync=yes ;;
esac
else
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([int i;],
[__sync_bool_compare_and_swap (&i, i, i);
__sync_lock_test_and_set (&i, 1);
__sync_lock_release (&i);])],
[libbacktrace_cv_sys_sync=yes],
[libbacktrace_cv_sys_sync=no])
fi])
BACKTRACE_SUPPORTS_THREADS=0
if test "$libbacktrace_cv_sys_sync" = "yes"; then
BACKTRACE_SUPPORTS_THREADS=1
AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
[Define to 1 if you have the __sync functions])
fi
AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
# Test for __atomic support.
AC_CACHE_CHECK([__atomic extensions],
[libbacktrace_cv_sys_atomic],
[if test -n "${with_target_subdir}"; then
libbacktrace_cv_sys_atomic=yes
else
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([int i;],
[__atomic_load_n (&i, __ATOMIC_ACQUIRE);
__atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
[libbacktrace_cv_sys_atomic=yes],
[libbacktrace_cv_sys_atomic=no])
fi])
if test "$libbacktrace_cv_sys_atomic" = "yes"; then
AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
[Define to 1 if you have the __atomic functions])
fi
# The library needs to be able to read the executable itself. Compile
# a file to determine the executable format. The awk script
# filetype.awk prints out the file type.
AC_CACHE_CHECK([output filetype],
[libbacktrace_cv_sys_filetype],
[filetype=
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([int i;], [int j;])],
[filetype=`${AWK} -f $srcdir/filetype.awk conftest.$ac_objext`],
[AC_MSG_FAILURE([compiler failed])])
libbacktrace_cv_sys_filetype=$filetype])
# Match the file type to decide what files to compile.
FORMAT_FILE=
backtrace_supports_data=yes
case "$libbacktrace_cv_sys_filetype" in
elf*) FORMAT_FILE="elf.lo" ;;
pecoff) FORMAT_FILE="pecoff.lo"
backtrace_supports_data=no
;;
macho*) FORMAT_FILE="macho.lo"
backtrace_supports_data=no
;;
*) AC_MSG_WARN([could not determine output file type])
FORMAT_FILE="unknown.lo"
backtrace_supported=no
;;
esac
AC_SUBST(FORMAT_FILE)
# ELF defines.
elfsize=
case "$libbacktrace_cv_sys_filetype" in
elf32) elfsize=32 ;;
elf64) elfsize=64 ;;
*) elfsize=unused
esac
AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
BACKTRACE_SUPPORTED=0
if test "$backtrace_supported" = "yes"; then
BACKTRACE_SUPPORTED=1
fi
AC_SUBST(BACKTRACE_SUPPORTED)
BACKTRACE_SUPPORTS_DATA=0
if test "$backtrace_supports_data" = "yes"; then
BACKTRACE_SUPPORTS_DATA=1
fi
AC_SUBST(BACKTRACE_SUPPORTS_DATA)
GCC_HEADER_STDINT(gstdint.h)
AC_CHECK_HEADERS(sys/mman.h)
if test "$ac_cv_header_sys_mman_h" = "no"; then
have_mmap=no
else
if test -n "${with_target_subdir}"; then
# When built as a GCC target library, we can't do a link test. We
# simply assume that if we have mman.h, we have mmap.
have_mmap=yes
case "${host}" in
spu-*-*|*-*-msdosdjgpp)
# The SPU does not have mmap, but it has a sys/mman.h header file
# containing "mmap_eaddr" and the mmap flags, confusing the test.
# DJGPP also has sys/man.h, but no mmap
have_mmap=no ;;
esac
else
AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
fi
fi
case "${host_os}" in
darwin*)
have_mmap=no ;;
esac
if test "$have_mmap" = "no"; then
VIEW_FILE=read.lo
ALLOC_FILE=alloc.lo
else
VIEW_FILE=mmapio.lo
AC_PREPROC_IFELSE([
#include <sys/mman.h>
#if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
#error no MAP_ANONYMOUS
#endif
], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
fi
AC_SUBST(VIEW_FILE)
AC_SUBST(ALLOC_FILE)
BACKTRACE_USES_MALLOC=0
if test "$ALLOC_FILE" = "alloc.lo"; then
BACKTRACE_USES_MALLOC=1
fi
AC_SUBST(BACKTRACE_USES_MALLOC)
# Check for dl_iterate_phdr.
AC_CHECK_HEADERS(link.h)
if test "$ac_cv_header_link_h" = "no"; then
have_dl_iterate_phdr=no
else
if test -n "${with_target_subdir}"; then
# When built as a GCC target library, we can't do a link test.
AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
[have_dl_iterate_phdr=no])
case "${host}" in
*-*-solaris2.10*)
# Avoid dl_iterate_phdr on Solaris 10, where it is in the
# header file but is only in -ldl.
have_dl_iterate_phdr=no ;;
esac
else
AC_CHECK_FUNC([dl_iterate_phdr], [have_dl_iterate_phdr=yes],
[have_dl_iterate_phdr=no])
fi
fi
if test "$have_dl_iterate_phdr" = "yes"; then
AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
fi
# Check for the fcntl function.
if test -n "${with_target_subdir}"; then
case "${host}" in
*-*-mingw*) have_fcntl=no ;;
spu-*-*) have_fcntl=no ;;
*) have_fcntl=yes ;;
esac
else
AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
fi
if test "$have_fcntl" = "yes"; then
AC_DEFINE([HAVE_FCNTL], 1,
[Define to 1 if you have the fcntl function])
fi
AC_CHECK_DECLS(strnlen)
# Check for getexecname function.
if test -n "${with_target_subdir}"; then
case "${host}" in
*-*-solaris2*) have_getexecname=yes ;;
*) have_getexecname=no ;;
esac
else
AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
fi
if test "$have_getexecname" = "yes"; then
AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
fi
AC_CACHE_CHECK([whether tests can run],
[libbacktrace_cv_sys_native],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
[libbacktrace_cv_sys_native=yes],
[libbacktrace_cv_sys_native=no],
[libbacktrace_cv_sys_native=no])])
AM_CONDITIONAL(NATIVE, test "$libbacktrace_cv_sys_native" = "yes")
if test "${multilib}" = "yes"; then
multilib_arg="--enable-multilib"
else
multilib_arg=
fi
AC_CONFIG_FILES(Makefile backtrace-supported.h)
# We need multilib support, but only if configuring for the target.
AC_CONFIG_COMMANDS([default],
[if test -n "$CONFIG_FILES"; then
if test -n "${with_target_subdir}"; then
# Multilibs need MULTISUBDIR defined correctly in certain makefiles so
# that multilib installs will end up installed in the correct place.
# The testsuite needs it for multilib-aware ABI baseline files.
# To work around this not being passed down from config-ml.in ->
# srcdir/Makefile.am -> srcdir/{src,libsupc++,...}/Makefile.am, manually
# append it here. Only modify Makefiles that have just been created.
#
# Also, get rid of this simulated-VPATH thing that automake does.
cat > vpsed << \_EOF
s!`test -f '$<' || echo '$(srcdir)/'`!!
_EOF
for i in $SUBDIRS; do
case $CONFIG_FILES in
*${i}/Makefile*)
#echo "Adding MULTISUBDIR to $i/Makefile"
sed -f vpsed $i/Makefile > tmp
grep '^MULTISUBDIR =' Makefile >> tmp
mv tmp $i/Makefile
;;
esac
done
rm vpsed
fi
fi
],
[
# Variables needed in config.status (file generation) which aren't already
# passed by autoconf.
SUBDIRS="$SUBDIRS"
])
AC_OUTPUT
此差异已折叠。
此差异已折叠。
/* Declarations and definitions of codes relating to the DWARF2 and
DWARF3 symbolic debugging information formats.
Copyright (C) 1992-2015 Free Software Foundation, Inc.
Written by Gary Funck (gary@intrepid.com) The Ada Joint Program
Office (AJPO), Florida State University and Silicon Graphics Inc.
provided support for this effort -- June 21, 1995.
Derived from the DWARF 1 implementation written by Ron Guilmette
(rfg@netcom.com), November 1990.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
/* This file is derived from the DWARF specification (a public document)
Revision 2.0.0 (July 27, 1993) developed by the UNIX International
Programming Languages Special Interest Group (UI/PLSIG) and distributed
by UNIX International. Copies of this specification are available from
UNIX International, 20 Waterview Boulevard, Parsippany, NJ, 07054.
This file also now contains definitions from the DWARF 3 specification
published Dec 20, 2005, available from: http://dwarf.freestandards.org. */
#ifndef _DWARF2_H
#define _DWARF2_H
#define DW_TAG(name, value) , name = value
#define DW_TAG_DUP(name, value) , name = value
#define DW_FORM(name, value) , name = value
#define DW_AT(name, value) , name = value
#define DW_AT_DUP(name, value) , name = value
#define DW_OP(name, value) , name = value
#define DW_OP_DUP(name, value) , name = value
#define DW_ATE(name, value) , name = value
#define DW_ATE_DUP(name, value) , name = value
#define DW_CFA(name, value) , name = value
#define DW_FIRST_TAG(name, value) enum dwarf_tag { \
name = value
#define DW_END_TAG };
#define DW_FIRST_FORM(name, value) enum dwarf_form { \
name = value
#define DW_END_FORM };
#define DW_FIRST_AT(name, value) enum dwarf_attribute { \
name = value
#define DW_END_AT };
#define DW_FIRST_OP(name, value) enum dwarf_location_atom { \
name = value
#define DW_END_OP };
#define DW_FIRST_ATE(name, value) enum dwarf_type { \
name = value
#define DW_END_ATE };
#define DW_FIRST_CFA(name, value) enum dwarf_call_frame_info { \
name = value
#define DW_END_CFA };
#include "dwarf2.def"
#undef DW_FIRST_TAG
#undef DW_END_TAG
#undef DW_FIRST_FORM
#undef DW_END_FORM
#undef DW_FIRST_AT
#undef DW_END_AT
#undef DW_FIRST_OP
#undef DW_END_OP
#undef DW_FIRST_ATE
#undef DW_END_ATE
#undef DW_FIRST_CFA
#undef DW_END_CFA
#undef DW_TAG
#undef DW_TAG_DUP
#undef DW_FORM
#undef DW_AT
#undef DW_AT_DUP
#undef DW_OP
#undef DW_OP_DUP
#undef DW_ATE
#undef DW_ATE_DUP
#undef DW_CFA
/* Flag that tells whether entry has a child or not. */
#define DW_children_no 0
#define DW_children_yes 1
#define DW_AT_stride_size DW_AT_bit_stride /* Note: The use of DW_AT_stride_size is deprecated. */
#define DW_AT_stride DW_AT_byte_stride /* Note: The use of DW_AT_stride is deprecated. */
/* Decimal sign encodings. */
enum dwarf_decimal_sign_encoding
{
/* DWARF 3. */
DW_DS_unsigned = 0x01,
DW_DS_leading_overpunch = 0x02,
DW_DS_trailing_overpunch = 0x03,
DW_DS_leading_separate = 0x04,
DW_DS_trailing_separate = 0x05
};
/* Endianity encodings. */
enum dwarf_endianity_encoding
{
/* DWARF 3. */
DW_END_default = 0x00,
DW_END_big = 0x01,
DW_END_little = 0x02,
DW_END_lo_user = 0x40,
DW_END_hi_user = 0xff
};
/* Array ordering names and codes. */
enum dwarf_array_dim_ordering
{
DW_ORD_row_major = 0,
DW_ORD_col_major = 1
};
/* Access attribute. */
enum dwarf_access_attribute
{
DW_ACCESS_public = 1,
DW_ACCESS_protected = 2,
DW_ACCESS_private = 3
};
/* Visibility. */
enum dwarf_visibility_attribute
{
DW_VIS_local = 1,
DW_VIS_exported = 2,
DW_VIS_qualified = 3
};
/* Virtuality. */
enum dwarf_virtuality_attribute
{
DW_VIRTUALITY_none = 0,
DW_VIRTUALITY_virtual = 1,
DW_VIRTUALITY_pure_virtual = 2
};
/* Case sensitivity. */
enum dwarf_id_case
{
DW_ID_case_sensitive = 0,
DW_ID_up_case = 1,
DW_ID_down_case = 2,
DW_ID_case_insensitive = 3
};
/* Calling convention. */
enum dwarf_calling_convention
{
DW_CC_normal = 0x1,
DW_CC_program = 0x2,
DW_CC_nocall = 0x3,
DW_CC_lo_user = 0x40,
DW_CC_hi_user = 0xff,
DW_CC_GNU_renesas_sh = 0x40,
DW_CC_GNU_borland_fastcall_i386 = 0x41,
/* This DW_CC_ value is not currently generated by any toolchain. It is
used internally to GDB to indicate OpenCL C functions that have been
compiled with the IBM XL C for OpenCL compiler and use a non-platform
calling convention for passing OpenCL C vector types. This value may
be changed freely as long as it does not conflict with any other DW_CC_
value defined here. */
DW_CC_GDB_IBM_OpenCL = 0xff
};
/* Inline attribute. */
enum dwarf_inline_attribute
{
DW_INL_not_inlined = 0,
DW_INL_inlined = 1,
DW_INL_declared_not_inlined = 2,
DW_INL_declared_inlined = 3
};
/* Discriminant lists. */
enum dwarf_discrim_list
{
DW_DSC_label = 0,
DW_DSC_range = 1
};
/* Line number opcodes. */
enum dwarf_line_number_ops
{
DW_LNS_extended_op = 0,
DW_LNS_copy = 1,
DW_LNS_advance_pc = 2,
DW_LNS_advance_line = 3,
DW_LNS_set_file = 4,
DW_LNS_set_column = 5,
DW_LNS_negate_stmt = 6,
DW_LNS_set_basic_block = 7,
DW_LNS_const_add_pc = 8,
DW_LNS_fixed_advance_pc = 9,
/* DWARF 3. */
DW_LNS_set_prologue_end = 10,
DW_LNS_set_epilogue_begin = 11,
DW_LNS_set_isa = 12
};
/* Line number extended opcodes. */
enum dwarf_line_number_x_ops
{
DW_LNE_end_sequence = 1,
DW_LNE_set_address = 2,
DW_LNE_define_file = 3,
DW_LNE_set_discriminator = 4,
/* HP extensions. */
DW_LNE_HP_negate_is_UV_update = 0x11,
DW_LNE_HP_push_context = 0x12,
DW_LNE_HP_pop_context = 0x13,
DW_LNE_HP_set_file_line_column = 0x14,
DW_LNE_HP_set_routine_name = 0x15,
DW_LNE_HP_set_sequence = 0x16,
DW_LNE_HP_negate_post_semantics = 0x17,
DW_LNE_HP_negate_function_exit = 0x18,
DW_LNE_HP_negate_front_end_logical = 0x19,
DW_LNE_HP_define_proc = 0x20,
DW_LNE_HP_source_file_correlation = 0x80,
DW_LNE_lo_user = 0x80,
DW_LNE_hi_user = 0xff
};
/* Sub-opcodes for DW_LNE_HP_source_file_correlation. */
enum dwarf_line_number_hp_sfc_ops
{
DW_LNE_HP_SFC_formfeed = 1,
DW_LNE_HP_SFC_set_listing_line = 2,
DW_LNE_HP_SFC_associate = 3
};
/* Type codes for location list entries.
Extension for Fission. See http://gcc.gnu.org/wiki/DebugFission. */
enum dwarf_location_list_entry_type
{
DW_LLE_GNU_end_of_list_entry = 0,
DW_LLE_GNU_base_address_selection_entry = 1,
DW_LLE_GNU_start_end_entry = 2,
DW_LLE_GNU_start_length_entry = 3
};
#define DW_CIE_ID 0xffffffff
#define DW64_CIE_ID 0xffffffffffffffffULL
#define DW_CIE_VERSION 1
#define DW_CFA_extended 0
#define DW_CHILDREN_no 0x00
#define DW_CHILDREN_yes 0x01
#define DW_ADDR_none 0
/* Source language names and codes. */
enum dwarf_source_language
{
DW_LANG_C89 = 0x0001,
DW_LANG_C = 0x0002,
DW_LANG_Ada83 = 0x0003,
DW_LANG_C_plus_plus = 0x0004,
DW_LANG_Cobol74 = 0x0005,
DW_LANG_Cobol85 = 0x0006,
DW_LANG_Fortran77 = 0x0007,
DW_LANG_Fortran90 = 0x0008,
DW_LANG_Pascal83 = 0x0009,
DW_LANG_Modula2 = 0x000a,
/* DWARF 3. */
DW_LANG_Java = 0x000b,
DW_LANG_C99 = 0x000c,
DW_LANG_Ada95 = 0x000d,
DW_LANG_Fortran95 = 0x000e,
DW_LANG_PLI = 0x000f,
DW_LANG_ObjC = 0x0010,
DW_LANG_ObjC_plus_plus = 0x0011,
DW_LANG_UPC = 0x0012,
DW_LANG_D = 0x0013,
/* DWARF 4. */
DW_LANG_Python = 0x0014,
/* DWARF 5. */
DW_LANG_Go = 0x0016,
DW_LANG_C_plus_plus_11 = 0x001a, /* dwarf5.20141029.pdf DRAFT */
DW_LANG_C11 = 0x001d,
DW_LANG_C_plus_plus_14 = 0x0021,
DW_LANG_Fortran03 = 0x0022,
DW_LANG_Fortran08 = 0x0023,
DW_LANG_lo_user = 0x8000, /* Implementation-defined range start. */
DW_LANG_hi_user = 0xffff, /* Implementation-defined range start. */
/* MIPS. */
DW_LANG_Mips_Assembler = 0x8001,
/* UPC. */
DW_LANG_Upc = 0x8765,
/* HP extensions. */
DW_LANG_HP_Bliss = 0x8003,
DW_LANG_HP_Basic91 = 0x8004,
DW_LANG_HP_Pascal91 = 0x8005,
DW_LANG_HP_IMacro = 0x8006,
DW_LANG_HP_Assembler = 0x8007
};
/* Names and codes for macro information. */
enum dwarf_macinfo_record_type
{
DW_MACINFO_define = 1,
DW_MACINFO_undef = 2,
DW_MACINFO_start_file = 3,
DW_MACINFO_end_file = 4,
DW_MACINFO_vendor_ext = 255
};
/* Names and codes for new style macro information. */
enum dwarf_macro_record_type
{
DW_MACRO_GNU_define = 1,
DW_MACRO_GNU_undef = 2,
DW_MACRO_GNU_start_file = 3,
DW_MACRO_GNU_end_file = 4,
DW_MACRO_GNU_define_indirect = 5,
DW_MACRO_GNU_undef_indirect = 6,
DW_MACRO_GNU_transparent_include = 7,
/* Extensions for DWZ multifile.
See http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open . */
DW_MACRO_GNU_define_indirect_alt = 8,
DW_MACRO_GNU_undef_indirect_alt = 9,
DW_MACRO_GNU_transparent_include_alt = 10,
DW_MACRO_GNU_lo_user = 0xe0,
DW_MACRO_GNU_hi_user = 0xff
};
/* @@@ For use with GNU frame unwind information. */
#define DW_EH_PE_absptr 0x00
#define DW_EH_PE_omit 0xff
#define DW_EH_PE_uleb128 0x01
#define DW_EH_PE_udata2 0x02
#define DW_EH_PE_udata4 0x03
#define DW_EH_PE_udata8 0x04
#define DW_EH_PE_sleb128 0x09
#define DW_EH_PE_sdata2 0x0A
#define DW_EH_PE_sdata4 0x0B
#define DW_EH_PE_sdata8 0x0C
#define DW_EH_PE_signed 0x08
#define DW_EH_PE_pcrel 0x10
#define DW_EH_PE_textrel 0x20
#define DW_EH_PE_datarel 0x30
#define DW_EH_PE_funcrel 0x40
#define DW_EH_PE_aligned 0x50
#define DW_EH_PE_indirect 0x80
/* Codes for the debug sections in a dwarf package (.dwp) file.
Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFissionDWP. */
enum dwarf_sect
{
DW_SECT_INFO = 1,
DW_SECT_TYPES = 2,
DW_SECT_ABBREV = 3,
DW_SECT_LINE = 4,
DW_SECT_LOC = 5,
DW_SECT_STR_OFFSETS = 6,
DW_SECT_MACINFO = 7,
DW_SECT_MACRO = 8,
DW_SECT_MAX = 8
};
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Return the name of a DW_TAG_ constant, or NULL if the value is not
recognized. */
extern const char *get_DW_TAG_name (unsigned int tag);
/* Return the name of a DW_AT_ constant, or NULL if the value is not
recognized. */
extern const char *get_DW_AT_name (unsigned int attr);
/* Return the name of a DW_FORM_ constant, or NULL if the value is not
recognized. */
extern const char *get_DW_FORM_name (unsigned int form);
/* Return the name of a DW_OP_ constant, or NULL if the value is not
recognized. */
extern const char *get_DW_OP_name (unsigned int op);
/* Return the name of a DW_ATE_ constant, or NULL if the value is not
recognized. */
extern const char *get_DW_ATE_name (unsigned int enc);
/* Return the name of a DW_CFA_ constant, or NULL if the value is not
recognized. */
extern const char *get_DW_CFA_name (unsigned int opc);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _DWARF2_H */
此差异已折叠。
此差异已折叠。
此差异已折叠。
# An awk script to determine the type of a file.
/\177ELF\001/ { if (NR == 1) { print "elf32"; exit } }
/\177ELF\002/ { if (NR == 1) { print "elf64"; exit } }
/\114\001/ { if (NR == 1) { print "pecoff"; exit } }
/\144\206/ { if (NR == 1) { print "pecoff"; exit } }
/\xFE\xED\xFA\xCE/ { if (NR == 1) { print "macho32"; exit } }
/\xCE\xFA\xED\xFE/ { if (NR == 1) { print "macho32"; exit } }
/\xFE\xED\xFA\xCF/ { if (NR == 1) { print "macho64"; exit } }
/\xCF\xFA\xED\xFE/ { if (NR == 1) { print "macho64"; exit } }
/\xCA\xFE\xBA\xBE/ { if (NR == 1) { print "macho-fat"; exit } }
/\xBE\xBA\xFE\xCA/ { if (NR == 1) { print "macho-fat"; exit } }
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -39,6 +39,7 @@ rustc_msan = { path = "../librustc_msan" }
rustc_tsan = { path = "../librustc_tsan" }
[build-dependencies]
cc = "1.0"
build_helper = { path = "../build_helper" }
[features]
......
此差异已折叠。
......@@ -98,6 +98,7 @@
Crate("parking_lot"),
Crate("parking_lot_core"),
Crate("polonius-engine"),
Crate("pkg-config"),
Crate("quick-error"),
Crate("rand"),
Crate("redox_syscall"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册