Skip to content

Commit 0638d15

Browse files
committed
chore: symbolize stack traces in tests upon crash
We disable address space randomization when building the binary and use addr2line to symbolize the stacktrace if it exists. Signed-off-by: Roman Gershman <[email protected]>
1 parent 267bd43 commit 0638d15

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ jobs:
100100
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
101101
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
102102
run: |
103+
# -no-pie to disable address randomization so we could symbolize stacktraces
103104
cmake -B ${GITHUB_WORKSPACE}/build \
104105
-DCMAKE_BUILD_TYPE=${{matrix.build-type}} \
105106
-GNinja \
106107
-DCMAKE_C_COMPILER="${{matrix.compiler.c}}" \
107108
-DCMAKE_CXX_COMPILER="${{matrix.compiler.cxx}}" \
108109
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_C_COMPILER_LAUNCHER=sccache \
109-
-DCMAKE_CXX_FLAGS="${{matrix.cxx_flags}}" -DWITH_AWS:BOOL=OFF \
110+
-DCMAKE_CXX_FLAGS="${{matrix.cxx_flags}} -no-pie" -DWITH_AWS:BOOL=OFF \
110111
-L
111112
cd ${GITHUB_WORKSPACE}/build && pwd
112113
du -hcs _deps/

.github/workflows/regression-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ jobs:
2929

3030
- name: Configure & Build
3131
run: |
32+
# -no-pie to disable address randomization so we could symbolize stacktraces
3233
cmake -B ${GITHUB_WORKSPACE}/build -DCMAKE_BUILD_TYPE=${{matrix.build-type}} -GNinja \
33-
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DPRINT_STACKTRACES_ON_SIGNAL=ON
34+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DPRINT_STACKTRACES_ON_SIGNAL=ON \
35+
-DCMAKE_CXX_FLAGS=-no-pie
3436
3537
cd ${GITHUB_WORKSPACE}/build && ninja dragonfly
3638
pwd

tests/dragonfly/instance.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ class DflyStartException(Exception):
4747
pass
4848

4949

50+
def symbolize_stack_trace(binary_path, lines):
51+
pattern = rb"@\s*(0x[0-9a-fA-F]+)"
52+
matcher = re.compile(pattern)
53+
addr2line_proc = subprocess.Popen(
54+
["/usr/bin/addr2line", "-fCa", "-e", binary_path], stdin=subprocess.PIPE
55+
)
56+
for line in lines:
57+
res = matcher.search(line)
58+
if res:
59+
g = res.group(1) + b"\n"
60+
addr2line_proc.stdin.write(g)
61+
62+
addr2line_proc.stdin.close()
63+
addr2line_proc.wait()
64+
65+
5066
class DflyInstance:
5167
"""
5268
Represents a runnable and stoppable Dragonfly instance
@@ -150,7 +166,7 @@ def _wait_for_server(self):
150166
sed_cmd = ["sed", "-u", "-e", sed_format]
151167
if self.params.buffered_out:
152168
sed_cmd.remove("-u")
153-
subprocess.Popen(sed_cmd, stdin=self.proc.stdout)
169+
self.sed_proc = subprocess.Popen(sed_cmd, stdin=self.proc.stdout, stdout=subprocess.PIPE)
154170

155171
def set_proc_to_none(self):
156172
self.proc = None
@@ -188,6 +204,17 @@ def stop(self, kill=False):
188204
proc.kill()
189205
proc.communicate()
190206
raise Exception("Unable to terminate DragonflyDB gracefully, it was killed")
207+
finally:
208+
sed_out = self.sed_proc.stdout.readlines()
209+
210+
# Deduplicate output - we somewhere duplicate the output, probably due
211+
# to tty redirections.
212+
seen = set()
213+
sed_out = [x for x in sed_out if not (x in seen or seen.add(x))]
214+
215+
for str in sed_out:
216+
print(str.decode())
217+
symbolize_stack_trace(proc.args[0], sed_out)
191218

192219
def _start(self):
193220
if self.params.existing_port:

0 commit comments

Comments
 (0)