boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
433 stars 74 forks source link

Missing backtrace.h on linux #108

Closed opelx closed 3 years ago

opelx commented 3 years ago

Compiling stacktrace on Linux (here fedora33 witj Clang 11) fails due to missing header backtrace.h. The official documentation states that there shall be a header:

-DBOOST_STACKTRACE_BACKTRACE_INCLUDE_FILE=</usr/lib/gcc/x86_64-linux-gnu/5/include/backtrace.h>

but there isn't:

$ ls -la /usr/lib/gcc/x86_64-redhat-linux/10/include/stack*
ls: cannot access '/usr/lib/gcc/x86_64-redhat-linux/10/include/stack*': No such file or directory

It seems, that this statement is old, a similar problem is shown FS#50262 - [gcc] GCC ships without libbacktrace. My package system doesn't show any additional backtrace or stacktrace packages related to gcc. man backtrace refers to .

What is the state on linux this time? Or miss I something?

apolukhin commented 3 years ago

If your Linux distro does not have a package with backtrace.h header then you have to manually install the libbacktrace from sources. References to that library are awailable on the same docs page

opelx commented 3 years ago

Thanks for your answer. I'm using CMake with FindBoost which fails to find backtrace.h. This library hasn't CMake support (probably will never get) out of the box. I have to build it into 3rd party dependency. All this results into an effort, which may comes obsolete since the offical linux libc way seems to be to use . Are there any plans to support this?

apolukhin commented 3 years ago

backtrace_symbols from execinfo.h just uses dlsym without demangling C++ symbols https://code.woboq.org/userspace/glibc/debug/backtracesyms.c.html

In other words, it is slightly worse than the default boost_stacktrace_basic https://www.boost.org/doc/libs/1_75_0/doc/html/stacktrace/configuration_and_build.html

major-mayer commented 3 years ago

If anybody encounters this problem on Arch Linux or any of it's derivatives, you can find libbacktrace in the AUR: https://aur.archlinux.org/packages/libbacktrace-git

opelx commented 3 years ago

Thank you. I close the issue. I have to include lib backtrace into my build process somehow if I want to get better traces than boost_stacktrace_basic.

zaufi commented 2 years ago

backtrace_symbols from execinfo.h just uses dlsym without demangling C++ symbols https://code.woboq.org/userspace/glibc/debug/backtracesyms.c.html

In other words, it is slightly worse than the default boost_stacktrace_basic https://www.boost.org/doc/libs/1_75_0/doc/html/stacktrace/configuration_and_build.html

But with __cxa_demangle it's very nice! At least for GCC... It'll be nice to have it as another alternative in the Boost::stacktrace library, please ;)

justusranvier commented 1 year ago

I found my way to this issue after discovering that CMake's FindBacktrace module points at <execinfo.h> and libbacktrace is not available for me to install.

An implementation that uses <execinfo.h> and __cxa_demangle would be very welcome improvement over the boost_stacktrace_basic implementation.

OrangeDog commented 3 months ago

Also with CMake, I had the problem of find_path not searching the internal include paths. This can help with that:

find_path(BACKTRACE_INCLUDE backtrace.h
        HINTS ${CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS}
        REQUIRED)

giving e.g.

BACKTRACE_INCLUDE:PATH=/usr/lib/gcc/x86_64-linux-gnu/12/include