If we fall back to DWARF processing trying to find a function name we deallocated the wrong object because of a copy/paste error. This part of the code was hit only very rarely, which made this bug undetected for a long time.
libstdc++ versions (e.g. 4.8.2) don't have the rvalue overload of
std::getline. This fixes this error when compiled with libstdc++ 4.8.2:
ext/backward-cpp/backward.hpp: In static member function 'static std::string backward::TraceResolverLinuxBase::get_argv0()':
ext/backward-cpp/backward.hpp:1031:66: error: no matching function for call to 'getline(std::ifstream, std::string&, char)'
std::getline(std::ifstream("/proc/self/cmdline"), argv0, '\0');
^
ext/backward-cpp/backward.hpp:1031:66: note: candidates are:
/usr/include/c++/4.8/bits/basic_string.h:2799:5: note: std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&, _CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]
getline(basic_istream<char>& __in, basic_string<char>& __str,
^
/usr/include/c++/4.8/bits/basic_string.h:2799:5: note: no known conversion for argument 1 from 'std::ifstream {aka std::basic_ifstream<char>}' to 'std::basic_istream<char>&'
This is useful for binaries (using backward-cpp) that are built with
relative source file paths. In such a situation, backward-cpp will
generally not be able to locate the source files. This change allows
the user to specify a delimited list of search paths in the following
environment variable:
BACKWARD_CXX_SOURCE_PREFIXES
The paths are separated by semicolons on Windows and colons otherwise.
When the environment variable is set, those search paths will be tried
first. If they do not yield any valid files then backward-cpp will
fall back to current behavior.
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.