osmith submitted this change.

View Change

Approvals: fixeria: Looks good to me, but someone else must approve Jenkins Builder: Verified daniel: Looks good to me, approved
scripts/wrapper_core_bt_on_error: new script

Add a wrapper script that runs a given program, and checks the exit
code. If it is not 0, and a core file appears, then load the coredump in
gdb and display its backtrace.

Change-Id: I9673abf3ae3b154505ea09237d37d7da4bf5d57f
---
A scripts/wrapper_core_bt_on_error.sh
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/scripts/wrapper_core_bt_on_error.sh b/scripts/wrapper_core_bt_on_error.sh
new file mode 100755
index 0000000..ca1eaef
--- /dev/null
+++ b/scripts/wrapper_core_bt_on_error.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright 2025 sysmocom - s.f.m.c. GmbH
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Run a program and check for coredumps if it does not exit with 0. If there
+# are any coredumps, then show the backtrace.
+msg() {
+ echo "[wrapper_core_bt_on_error] $@"
+}
+
+if [ $# -lt 1 ]; then
+ echo "usage: wrapper_core_bt_on_error.sh PROGRAM [ARG1 [ARG2 […]]]"
+ exit 1
+fi
+
+ulimit -c unlimited
+
+"$@"
+RC=$?
+
+if [ "$RC" != 0 ]; then
+ for i in $(find -name 'core' -type f); do
+ msg "Found coredump: $i"
+ execfn="$(file "$i" | grep -P -o "execfn: '.*?'" | cut -d "'" -f 2)"
+ if [ -z "$execfn" ] || ! [ -e "$execfn" ]; then
+ msg "Failed to get execfn, ignoring..."
+ continue
+ fi
+
+ echo
+ gdb --batch \
+ "$execfn" \
+ "$i" \
+ -ex bt \
+ | tee "$i.backtrace"
+ echo
+ done
+ exit $RC
+fi

To view, visit change 41155. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I9673abf3ae3b154505ea09237d37d7da4bf5d57f
Gerrit-Change-Number: 41155
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>