Skip to content

Commit

Permalink
Add stacktrace (#674)
Browse files Browse the repository at this point in the history
Related to #659 

Adds backtrace printing to SIGSEGV signal handling. Tries to print file
and line number with libbacktrace, falls back to using standard
backtrace when debug info is unavailable.

Before:
<img width="715" alt="Screenshot 2024-07-11 at 15 58 52"
src="https://github.com/urbit/vere/assets/22086553/3ba89d96-c50c-40a5-8fd4-f6e636b8aec3">

After (with dsyms):
<img width="715" alt="Screenshot 2024-07-24 at 17 11 56"
src="https://github.com/user-attachments/assets/b333516f-c36f-48ce-afd2-95de9f812843">

After (without dsyms):
<img width="715" alt="Screenshot 2024-07-24 at 17 14 31"
src="https://github.com/user-attachments/assets/59956429-2fc7-478e-a05d-1807db21b18f">
  • Loading branch information
pkova authored Sep 16, 2024
2 parents 5fcf117 + df8e34e commit 3761ed0
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 29 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ jobs:
#
- uses: actions/checkout@v3

- name: Set swap space
if: ${{ matrix.target == 'linux-x86_64' || matrix.target == 'linux-aarch64'}}
run: |
echo "Memory and swap:"
free -h
echo
swapon --show
echo
export SWAP_FILE=$(swapon --show=NAME | tail -n 1)
if test -z "${SWAP_FILE}"; then
export SWAP_FILE=/swapfile
else
sudo swapoff -a
sudo rm "${SWAP_FILE}"
fi
sudo fallocate -l 10G "${SWAP_FILE}"
sudo chmod 600 "${SWAP_FILE}"
sudo mkswap "${SWAP_FILE}"
sudo swapon "${SWAP_FILE}"
echo "Memory and swap:"
free -h
echo
swapon --show
echo
- name: chown /usr/local
if: ${{ matrix.target == 'linux-x86_64' || matrix.target == 'linux-aarch64'}}
run: |
Expand All @@ -64,7 +91,7 @@ jobs:
- name: Set up build cache
uses: actions/cache@v3
with:
key: ${{ matrix.target }}-cache
key: ${{ matrix.target }}-cache-1
path: |
# # Cache bazel path on Linux.
~/.cache/bazel/_bazel_$(whoami)
Expand Down
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ string_flag(
# Version flag for gcc.
string_flag(
name = "gcc_version",
# musl-cross-make uses `gcc-9.4.0` by default.
build_setting_default = "9.4.0",
# musl-cross-make uses `gcc-11.4.0` by default.
build_setting_default = "11.4.0",
visibility = ["//visibility:public"],
)

Expand Down
18 changes: 18 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ versioned_http_file(
version = "255fb1ca8206072f1d09425f0db61ecfe7ff5b17",
)

versioned_http_archive(
name = "libbacktrace",
build_file = "//bazel/third_party/libbacktrace:libbacktrace.BUILD",
sha256 = "609c17352ec38eaf5ff6618fcbfb38cd8fa0e94a15a0d9aa259df514bbf47fcd",
url = "https://github.com/ianlancetaylor/libbacktrace/archive/{version}.tar.gz",
strip_prefix = "libbacktrace-{version}",
version = "4ead348bb45f753121ca0bd44170ff8352d4c514",
)

versioned_http_archive(
name = "libunwind",
build_file = "//bazel/third_party/libunwind:libunwind.BUILD",
sha256 = "ddf0e32dd5fafe5283198d37e4bf9decf7ba1770b6e7e006c33e6df79e6a6157",
url = "https://github.com/libunwind/libunwind/releases/download/v1.8.1/libunwind-1.8.1.tar.gz",
strip_prefix = "libunwind-{version}",
version = "1.8.1",
)

versioned_http_archive(
name = "lmdb",
build_file = "//bazel/third_party/lmdb:lmdb.BUILD",
Expand Down
25 changes: 8 additions & 17 deletions bazel/common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ string_flag = rule(

def vere_library(copts = [], linkopts = [], **kwargs):
native.cc_library(
copts = copts + select({
copts = copts + [
"-fno-omit-frame-pointer",
] + select({
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
"//conditions:default": ["-O3", "-g"]
}) + select({
"//:lto": ['-flto'],
"//:thinlto": ['-flto=thin'],
"//conditions:default": []
}) + select({
# Don't include source level debug info on macOS. See
# https://github.com/urbit/urbit/issues/5561 and
# https://github.com/urbit/vere/issues/131.
"//:debug": [],
"@platforms//os:linux": ["-g"],
"//conditions:default": [],
}),
linkopts = linkopts + ['-g'] + select({
"//:lto": ['-flto'],
Expand All @@ -38,17 +32,14 @@ def vere_library(copts = [], linkopts = [], **kwargs):

def vere_binary(copts = [], linkopts = [], **kwargs):
native.cc_binary(
copts = copts + select({
copts = copts + [
"-fno-omit-frame-pointer",
] + select({
"//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."],
"//conditions:default": ["-O3"]
"//conditions:default": ["-O3", "-g"]
}) + select({
"//:lto": ['-flto'],
"//:thinlto": ['-flto=thin'],
"//conditions:default": []
}) + select({
"//:debug": [],
"@platforms//os:linux": ["-g"],
"//conditions:default": [],
}),
linkopts = linkopts + ['-g'] + select({
"//:lto": ['-flto'],
Expand Down
6 changes: 6 additions & 0 deletions bazel/third_party/expat/expat.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ configure_make(
"@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"],
"//conditions:default": ["--jobs=`nproc`"],
}),
configure_options = [
] + select({
"@//:linux_aarch64": ["--host=aarch64-linux-musl"],
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
"//conditions:default": [],
}),
copts = ["-O3"],
lib_source = ":all",
out_static_libs = ["libexpat.a"],
Expand Down
Empty file.
25 changes: 25 additions & 0 deletions bazel/third_party/libbacktrace/libbacktrace.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "all",
srcs = glob(["**"]),
)

configure_make(
name = "libbacktrace",
args = [
] + select({
"@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"],
"//conditions:default": ["--jobs=`nproc`"],
}),
configure_options = [
] + select({
"@//:linux_aarch64": ["--host=aarch64-linux-musl"],
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
"//conditions:default": [],
}),
copts = ["-O3"],
lib_source = ":all",
out_static_libs = ["libbacktrace.a"],
visibility = ["//visibility:public"],
)
Empty file.
25 changes: 25 additions & 0 deletions bazel/third_party/libunwind/libunwind.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "all",
srcs = glob(["**"]),
)

configure_make(
name = "libunwind",
args = select({
"@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"],
"//conditions:default": ["--jobs=`nproc`"],
}),
configure_options = [
"--enable-debug-frame",
] + select({
"@//:linux_aarch64": ["--host=aarch64-linux-musl"],
"@//:linux_x86_64": ["--host=x86_64-linux-musl"],
"//conditions:default": [],
}),
copts = ["-O3 -g"],
lib_source = ":all",
out_static_libs = ["libunwind.a"],
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion bazel/third_party/urcrypt/urcrypt.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ configure_make(
copts = [
"-Wall",
"-g",
"-O3",
"-O2",
],
deps = [
"@aes_siv",
Expand Down
8 changes: 6 additions & 2 deletions bazel/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ toolchain(
# so introduces a circular dependency during Bazel C/C++ toolchain resolution.

# musl-cross-make builds musl-libc-compatible gcc toolchains from source.
_musl_cross_make_version = "fe915821b652a7fa37b34a596f47d8e20bc72338"
_musl_cross_make_version = "99f2cbc7e230f72bde3394be3ebd50497cb53e89"

_musl_cross_make_archive = "https://github.com/richfelker/musl-cross-make/archive/{}.tar.gz".format(_musl_cross_make_version)
_musl_cross_make_archive = "https://github.com/ripperi/musl-cross-make/archive/{}.tar.gz".format(_musl_cross_make_version)

genrule(
name = "install-aarch64-linux-musl-gcc",
Expand All @@ -349,6 +349,8 @@ genrule(
echo ' tar -xf {}.tar.gz' >> $@
echo ' archive=musl-cross-make-{}' >> $@
echo ' echo OUTPUT=$$aarch64_linux_musl_install > $$archive/config.mak' >> $@
echo ' echo GCC_VER=11.4.0 >> $$archive/config.mak' >> $@
echo ' echo MUSL_VER=1.2.5 >> $$archive/config.mak' >> $@
echo ' TARGET=aarch64-linux-musl make -s -C$$archive -j`nproc`' >> $@
echo ' sudo TARGET=aarch64-linux-musl make -s -C$$archive -j`nproc` install' >> $@
echo ' sudo chown --recursive $$USER $$aarch64_linux_musl_install' >> $@
Expand Down Expand Up @@ -382,6 +384,8 @@ genrule(
echo ' tar -xf {}.tar.gz' >> $@
echo ' archive=musl-cross-make-{}' >> $@
echo ' echo OUTPUT=$$x86_64_linux_musl_install > $$archive/config.mak' >> $@
echo ' echo GCC_VER=11.4.0 >> $$archive/config.mak' >> $@
echo ' echo MUSL_VER=1.2.5 >> $$archive/config.mak' >> $@
echo ' TARGET=x86_64-linux-musl make -s -C$$archive -j`nproc`' >> $@
echo ' sudo TARGET=x86_64-linux-musl make -s -C$$archive -j`nproc` install' >> $@
echo ' sudo chown --recursive $$USER $$x86_64_linux_musl_install' >> $@
Expand Down
7 changes: 6 additions & 1 deletion pkg/noun/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ vere_library(
"//pkg/ent",
"//pkg/ur",
"@gmp",
"@libbacktrace",
"@murmur3",
"@openssl",
"@pdjson",
"@sigsegv",
"@softfloat",
"@urcrypt",
"@whereami",
] + select({
"@platforms//os:macos": ["//pkg/noun/platform/darwin"],
"@platforms//os:linux": ["//pkg/noun/platform/linux"],
"@platforms//os:linux": [
"//pkg/noun/platform/linux",
"@libunwind",
],
"//conditions:default": [],
}),
)
Expand Down
Loading

0 comments on commit 3761ed0

Please sign in to comment.