osmith has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ci/+/41155?usp=email )


Change subject: scripts/wrapper_core_bt_on_error: new script
......................................................................

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(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ci refs/changes/55/41155/1

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 https://gerrit.osmocom.org/c/osmo-ci/+/41155?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I9673abf3ae3b154505ea09237d37d7da4bf5d57f
Gerrit-Change-Number: 41155
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>

Reply via email to