roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.06k stars 213 forks source link

Implement backtrace printing for non-glibc targets #242

Closed gavv closed 5 years ago

gavv commented 5 years ago

Currently we have three backtrace printing implementations:

./src/modules/roc_core/target_glibc/roc_core/backtrace.cpp
./src/modules/roc_core/target_bionic/roc_core/backtrace.cpp
./src/modules/roc_core/target_musl/roc_core/backtrace.cpp

(glibc-like libc on Linux and macOs; bionic libc on Android; musl libc on Linux)

The first one uses execinfo.h which is not available in bionic and musl. The rest two are currently no-op. It would be nice to implement them too:

In both cases, we need to implement two functions: print_backtrace() and print_backtrace_emergency(). The first one should print backtrace to stderr and if possible also perform demangling. The second one is a signal-safe version of the first one. It should not use stdio and should not allocate memory, so it likely can't perform demangling.

hrishikeshSuresh commented 5 years ago

I would like to work on this, if no one else has been assigned.

gavv commented 5 years ago

@hrishikeshSuresh you're welcome! Nobody is assigned.

gavv commented 5 years ago

PR is merged to develop.

gavv commented 5 years ago

Further experiments showed that the newly merged libunwind version performs better than the existing glibc version. In the glibc version, sometimes some addresses are not resolved to function names and so the backtrace is a bit incomplete. The glibc version also has some technical problems with the implementation.

I decided to remove the glibc version and just use libunwind everywhere except android. It is now enabled by default. The only glibc-specific code remained is demangling. I've extracted this piece and reused it in both libunwind and bionic versions. See this commit for details: 2ee625a6ef8ca3728c1f25a06410c5ffce59f953.

On macos, libunwind is provided as a part of the xcode toolchain. It's not the same library as libunwind on Linux, but it provides a compatible API, at least one covering our needs. So on macos, we also will use libunwind the same way, except that we will not try to search it using pkg-config or to download and build it, but instead assume that is always available. See this commit: 4d27883297b9b6fddab3805da64cef990c0e4265.

These changes are merged into develop.

gavv commented 5 years ago

So now we have backtrace printing on all supported platforms and I'm closing this.

Thanks @hrishikeshSuresh :)

hrishikeshSuresh commented 5 years ago

Oh that's great! You're welcome @gavv ! :)