add option to use libbacktrace for backtraces in crash reports#3034
add option to use libbacktrace for backtraces in crash reports#3034zuiderkwast merged 7 commits intovalkey-io:unstablefrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3034 +/- ##
============================================
- Coverage 74.71% 0 -74.72%
============================================
Files 129 0 -129
Lines 71331 0 -71331
============================================
- Hits 53295 0 -53295
+ Misses 18036 0 -18036 🚀 New features to boost your workflow:
|
8335cdd to
bbe25bf
Compare
|
This looks nice. Should we explore an option of not vendoring this? The change is pretty huge. |
35b396c to
5250809
Compare
|
I suppose it's worth considering not vendoring this. How would we structure it in that case? I somewhat fixed mac OS support, but it's more difficult to support the platform. One must run dsymutil to generate debug info, and LTO causes this to fail. It's coded to fall back to the old logic if debug info isn't found or didn't generate useful symbols. macos fallback behavior: |
I agree, it's pretty huge and entirely optional. Let the github action jobs install it using package managers if possible. It seems to be packaged for some (most?) distros: It'd also be okay to download, build and install it from source in the CI jobs. Don't add such download logic in the Makefiles though. It can be in the yaml files. When building Valkey with USE_LIBBACKTRACE, we can require it to be installed in the system already. Check the expected locations. Possibly we could allow specifying a path to it in a make variable too if it's required.
Seems fine if it doesn't look exactly the same as in other OSes. Also fine if it's not available on all platforms. |
There was a problem hiding this comment.
Pull request overview
This PR integrates libbacktrace as an optional dependency to produce richer, symbolized stack traces (with file/line and static functions) in crash reports, and wires it through the build system and CI.
Changes:
- Adds an optional
USE_LIBBACKTRACE=yesbuild flag that vendored-builds and links a static libbacktrace library, definingUSE_LIBBACKTRACEfor the server build. - Enhances
logStackTraceand related helpers insrc/debug.cto fork a helper process that uses libbacktrace to symbolize previously-captured PCs, with a fallback tobacktrace_symbols_fd. - Updates README and CI/daily/external workflows to document and exercise the new option, and adds ignore patterns for libtool artifacts.
Reviewed changes
Copilot reviewed 72 out of 79 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/debug.c | Adds libbacktrace-backed symbolization via symbolizeWithLibbacktrace, and switches stack trace printing to use it (with fallback) when USE_LIBBACKTRACE is enabled. |
| src/Makefile | Introduces USE_LIBBACKTRACE option, adjusting FINAL_CFLAGS, FINAL_LIBS, and dependency targets to build/link the vendored libbacktrace. |
| deps/Makefile | Adds libbacktrace target and includes it in distclean, so vendored libbacktrace is configured/built/cleaned as part of deps. |
| deps/libbacktrace/unknown.c | Part of upstream libbacktrace: default fileline resolution when file format is unknown. |
| deps/libbacktrace/unittest.c | Upstream libbacktrace unit test for vector allocation/release behavior. |
| deps/libbacktrace/ttest.c | Upstream libbacktrace multi-threaded backtrace test. |
| deps/libbacktrace/testlib.h | Upstream helper declarations for libbacktrace tests (structs, callbacks). |
| deps/libbacktrace/testlib.c | Upstream helper implementations used across libbacktrace tests. |
| deps/libbacktrace/test_format.c | Upstream test harness for libbacktrace’s externally visible interfaces. |
| deps/libbacktrace/test-driver | Upstream Automake-style test driver script used by libbacktrace tests. |
| deps/libbacktrace/stest.c | Upstream test for libbacktrace’s internal sort function. |
| deps/libbacktrace/state.c | Upstream implementation of backtrace_create_state. |
| deps/libbacktrace/sort.c | Upstream in-place qsort implementation used by libbacktrace. |
| deps/libbacktrace/simple.c | Upstream implementation of backtrace_simple using _Unwind_Backtrace. |
| deps/libbacktrace/read.c | Upstream non-mmap file view helper for platforms without mmap. |
| deps/libbacktrace/print.c | Upstream helper that prints a formatted backtrace to a FILE *. |
| deps/libbacktrace/posix.c | Upstream POSIX I/O helpers (backtrace_open/close). |
| deps/libbacktrace/nounwind.c | Upstream stub implementation when unwind library is unavailable. |
| deps/libbacktrace/mtest.c | Upstream minidebuginfo / build-id symbol resolution test. |
| deps/libbacktrace/move-if-change | Upstream helper script for conditional file moves. |
| deps/libbacktrace/mmapio.c | Upstream mmap-based file viewing helper. |
| deps/libbacktrace/mmap.c | Upstream mmap-based allocator used by libbacktrace. |
| deps/libbacktrace/missing | Upstream helper wrapper for potentially-missing GNU tools. |
| deps/libbacktrace/instrumented_alloc.c | Upstream allocation-failure-instrumented allocator for libbacktrace tests. |
| deps/libbacktrace/install-debuginfo-for-buildid.sh.in | Upstream helper script to install debug info by build-id for testing. |
| deps/libbacktrace/filetype.awk | Upstream AWK helper for detecting object file format. |
| deps/libbacktrace/filenames.h | Upstream header for filename/path utility macros. |
| deps/libbacktrace/fileline.c | Upstream core implementation for mapping PCs to file/line/function (DWARF + OS-specific discovery). |
| deps/libbacktrace/edtest2.c | Upstream part of allocation stress tests for libbacktrace. |
| deps/libbacktrace/edtest.c | Upstream allocation stress test driver for libbacktrace. |
| deps/libbacktrace/config/warnings.m4 | Upstream Autoconf macro to configure compiler warning flags. |
| deps/libbacktrace/config/unwind_ipinfo.m4 | Upstream macro to detect _Unwind_GetIPInfo availability. |
| deps/libbacktrace/config/override.m4 | Upstream overrides/fixes for older Autoconf behavior. |
| deps/libbacktrace/config/multi.m4 | Upstream multilib configuration macro. |
| deps/libbacktrace/config/lt~obsolete.m4 | Upstream libtool compatibility/obsolete macro definitions. |
| deps/libbacktrace/config/ltversion.m4 | Upstream libtool version metadata macro. |
| deps/libbacktrace/config/ltsugar.m4 | Upstream libtool m4 convenience macros. |
| deps/libbacktrace/config/ltoptions.m4 | Upstream libtool option-handling macros. |
| deps/libbacktrace/config/lead-dot.m4 | Upstream macro to detect leading-dot filename support. |
| deps/libbacktrace/config/enable.m4 | Upstream macro for standardized --enable-* handling. |
| deps/libbacktrace/config.h.in | Upstream Autoconf template header for libbacktrace configuration. |
| deps/libbacktrace/compile | Upstream wrapper script for compilers without -c -o. |
| deps/libbacktrace/backtrace.h | Upstream public libbacktrace API header. |
| deps/libbacktrace/backtrace.c | Upstream main implementation using _Unwind_Backtrace. |
| deps/libbacktrace/backtrace-supported.h.in | Upstream header template indicating libbacktrace capabilities on the platform. |
| deps/libbacktrace/atomic.c | Upstream fallback implementations for atomic operations. |
| deps/libbacktrace/allocfail.sh | Upstream shell harness for allocation-failure tests. |
| deps/libbacktrace/allocfail.c | Upstream allocation-failure test program. |
| deps/libbacktrace/alloc.c | Upstream malloc-based allocator for libbacktrace when mmap is unavailable. |
| deps/libbacktrace/README.md | Upstream documentation for libbacktrace usage and support matrix. |
| deps/libbacktrace/LICENSE | Upstream BSD-style license for libbacktrace. |
| deps/libbacktrace/.gitignore | Ignores libbacktrace build artifacts under the vendored directory. |
| deps/Makefile | Adds libbacktrace to the deps build/distclean workflow, configuring it as a static, non-shared dependency. |
| README.md | Documents USE_LIBBACKTRACE=yes as a build option for enhanced stack traces. |
| .gitignore | Adds patterns for libtool-generated *.lo and *.la files. |
| .github/workflows/external.yml | Builds external tests with USE_LIBBACKTRACE=yes so external server runs use symbolized stack traces. |
| .github/workflows/daily.yml | Updates all relevant daily test builds to compile with USE_LIBBACKTRACE=yes. |
| .github/workflows/coverity.yml | Runs Coverity analysis on a build that includes libbacktrace integration. |
| .github/workflows/codecov.yml | Runs coverage build with libbacktrace enabled to validate the integration under coverage instrumentation. |
| .github/workflows/ci.yml | Ensures main CI builds (including sanitizers, RDMA, TLS, 32‑bit, Alpine, etc.) exercise the libbacktrace-enabled build path. |
9de343b to
53a56ca
Compare
| git clone https://github.com/ianlancetaylor/libbacktrace.git /tmp/libbacktrace && git -C /tmp/libbacktrace checkout b9e40069c0b47a722286b94eb5231f7f05c08713 | ||
| cd /tmp/libbacktrace && ./configure && make && sudo make install | ||
| cd $GITHUB_WORKSPACE | ||
| make -j4 all-with-unit-tests SERVER_CFLAGS='-Werror' BUILD_TLS=yes USE_FAST_FLOAT=yes USE_LIBBACKTRACE=yes |
There was a problem hiding this comment.
Idea:
- name: Install libbacktrace
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ianlancetaylor/libbacktrace
ref: b9e40069c0b47a722286b94eb5231f7f05c08713
path: libbacktrace
- run: cd libbacktrace && ./configure && make && sudo make install
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: make
# Fail build if there are warnings
# build with TLS just for compilation coverage
run: make -j4 all-with-unit-tests SERVER_CFLAGS='-Werror' BUILD_TLS=yes USE_FAST_FLOAT=yes USE_LIBBACKTRACE=yesThere was a problem hiding this comment.
oops, I didn't do this yet 👀
There was a problem hiding this comment.
Oops, I missed that it wasn't done yet.
zuiderkwast
left a comment
There was a problem hiding this comment.
Looks like this is ready to merge. Thanks!
In the future we should probably update the actions/checkout to latest (6.0.2).
I wonder if we can avoid some of the duplication if we use matrix more, but that's too is a future improvement.
Signed-off-by: Rain Valentine <rsg000@gmail.com>
Signed-off-by: Rain Valentine <rsg000@gmail.com>
Signed-off-by: Rain Valentine <rsg000@gmail.com>
Signed-off-by: Rain Valentine <rsg000@gmail.com>
Signed-off-by: Rain Valentine <rsg000@gmail.com>
f9688df to
3c65f4e
Compare
…rrupted despite WNOHANG) Signed-off-by: Rain Valentine <rsg000@gmail.com>
3c65f4e to
c919084
Compare
Signed-off-by: Rain Valentine <rsg000@gmail.com>
This PR enables `USE_LIBBACKTRACE=yes` across all CI builds and builds upon the changes introduced in #3034. Alpine-based jobs previously attempted to install `libbacktrace-dev`, which does not exist in Alpine’s apk repositories. This caused these two errors in the daily tests below: - https://github.com/valkey-io/valkey/actions/runs/22045858351/job/63694456995 - https://github.com/valkey-io/valkey/actions/runs/22045858351/job/63694457018 To resolve this, Alpine jobs now build GNU libbacktrace from source inside the container before compiling Valkey. This aligns Alpine behavior with other environments (Ubuntu jobs) and now avoids utilizing non-existent Alpine packages. An alternative approach we can consider is to disable `USE_LIBBACKTRACE` for Alpine-based tests. Signed-off-by: Nikhil Manglore <nmanglor@amazon.com>
…y-io#3034) With this we get more detailed backtrace information, including information about static functions. Off by default - to enable you must enable at compile time: make USE_LIBBACKTRACE=yes Signed-off-by: Rain Valentine <rsg000@gmail.com>
This PR enables `USE_LIBBACKTRACE=yes` across all CI builds and builds upon the changes introduced in valkey-io#3034. Alpine-based jobs previously attempted to install `libbacktrace-dev`, which does not exist in Alpine’s apk repositories. This caused these two errors in the daily tests below: - https://github.com/valkey-io/valkey/actions/runs/22045858351/job/63694456995 - https://github.com/valkey-io/valkey/actions/runs/22045858351/job/63694457018 To resolve this, Alpine jobs now build GNU libbacktrace from source inside the container before compiling Valkey. This aligns Alpine behavior with other environments (Ubuntu jobs) and now avoids utilizing non-existent Alpine packages. An alternative approach we can consider is to disable `USE_LIBBACKTRACE` for Alpine-based tests. Signed-off-by: Nikhil Manglore <nmanglor@amazon.com>
With this we get more detailed backtrace information, including information about static functions. Off by default - to enable you must enable at compile time:
make USE_LIBBACKTRACE=yesbefore:
after: