osmith has submitted this change. ( https://gerrit.osmocom.org/c/docker-playground/+/42136?usp=email )
Change subject: common/wrapper_core_bt_on_error: import ......................................................................
common/wrapper_core_bt_on_error: import
Import this script from osmo-ci dfa9fcca ("scripts/wrapper_core_bt_on_error: new script"), so it can be used in ttcn3-asterisk-ims-ue-test in a follow-up patch.
Change-Id: I773ff8b8c07c96e1b5b417fa28518ac7dc2e14ec --- A common/wrapper_core_bt_on_error.sh 1 file changed, 38 insertions(+), 0 deletions(-)
Approvals: pespin: Looks good to me, approved fixeria: Looks good to me, but someone else must approve Jenkins Builder: Verified jolly: Looks good to me, but someone else must approve
diff --git a/common/wrapper_core_bt_on_error.sh b/common/wrapper_core_bt_on_error.sh new file mode 100755 index 0000000..ca1eaef --- /dev/null +++ b/common/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