Tests executables made several assumptions that are only valid on
some system/compiler:
* That the main function is found even in a shared library (not true
on windows). To fix this, test_main is now an ojbect library
* That the extern test_registry in test.cpp will be initialized
before any actual test uses it. This was either a lucky coincidence
on linux, or being related to the variable being initialized in a
shared library. The variable is now initialized by a function,
guarantaaing initialization order.
* That test.hpp is only inluded once per binary, which was only true
because it was once part of a DLL, once the executable, hiding ODR
violations. As now it's linked twice within the same binary, some
functions had to be made inline.
* not is not a valid C++ operator, replaced all occurences with !
MIPS didn't export regs at mcontext_t so we need to cast it as sigcontext.
All test passed on my mips64el machine.
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Linux is not synonymous with glibc. Alpine linux (among others) uses
libmusl as the standard C library. Alpine/libmusl doesn't have
backtrace, dladdr1, execinfo.h or error.h. It does have libunwind
and program_invocation_name and libdwarf and libelf are available as
packages.
This patch makes backward-cpp work on Alpine linux (and hopefully
others that rely on libmusl).
This patch makes dladdr1 dependent on the __GLIBC__ pp-symbol
(rather than __ANDROID__).
It uses __has_include (protected by a defined()) rather than __APPLE__
to decide whether to include <error.h> in _test_main.cpp.
returning a `const T` as opposed to `const T&` serves little purpose and is most likely not what the writer intended.
This change was called out by clang-tidy.
The comon practice in cmake to allow to specify the libdir or
includedir using GNUInstallDirs which introduces the following
options:
* CMAKE_INSTALL_INCLUDEDIR
* CMAKE_INSTALL_LIBDIR
The main motivation behind this change is ability to use /usr/lib64
instead of /usr/lib as a libdir.
When iterating through all the CU DIEs, only inspect those that have the
DW_TAG_compile_unit tag. When finishing the iteration, only keep going
to reset libdwarf's internal CU iterator if we found a DIE.
This allows using each definition (resulting from BackwardConfig.cmake)
separately, e.g., in conjunction with cmake's configure_file() command
and thus can be defined in a cmake-generated source file before a build.
Example:
Config.h.in
===========
#cmakedefine01 BACKWARD_HAS_UNWIND
#cmakedefine01 BACKWARD_HAS_BACKTRACE
#cmakedefine01 BACKWARD_HAS_BACKTRACE_SYMBOL
#cmakedefine01 BACKWARD_HAS_DW
#cmakedefine01 BACKWARD_HAS_BFD
#cmakedefine01 BACKWARD_HAS_DWARF
CMakeLists.txt:
===============
include(BackwardConfig)
configure_file( "${PROJECT_SOURCE_DIR}/Config.h.in"
"${PROJECT_BINARY_DIR}/Config.h" )
SomeProjectFile.C:
==================
#include "Config.h" // generated by cmake based on Config.h.in
#include "backward.hpp" // backward-cpp now configured based on BackwardConfig.cmake
using namespace backward;
StackTrace st; st.load_here(32);
Printer p; p.print(st);