ci: Improve OpenBSD core dump backtrace handling.
authorThomas Munro <tmunro@postgresql.org>
Thu, 6 Nov 2025 04:25:04 +0000 (17:25 +1300)
committerThomas Munro <tmunro@postgresql.org>
Thu, 6 Nov 2025 04:49:22 +0000 (17:49 +1300)
Since OpenBSD core dumps do not embed executable paths, the script now
searches for the corresponding binary manually within the specified
directory before invoking LLDB.  This is imperfect but should find the
right executable in practice, as needed for meaningful backtraces.

Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Discussion: https://postgr.es/m/CAN55FZ36R74TZ8RKsFueYwLxGKDAm3LU2FHM_ZUCSB6imd3vYA@mail.gmail.com
Backpatch-through: 18

.cirrus.tasks.yml
src/tools/ci/cores_backtrace.sh

index 119bc1af94c1935afd9a0611cda31d95ced48396..dd24afd3567017b42825797d6af9aa3a34758be8 100644 (file)
@@ -290,6 +290,7 @@ task:
         PKGCONFIG_PATH: '/usr/lib/pkgconfig:/usr/local/lib/pkgconfig'
         UUID: -Duuid=e2fs
         TCL: -Dtcl_version=tcl86
+        CORE_DUMP_EXECUTABLE_DIR: $CIRRUS_WORKING_DIR/build/tmp_install/usr/local/pgsql/bin
       setup_additional_packages_script: |
         #pkg_add -I ...
       # Always core dump to ${CORE_DUMP_DIR}
@@ -352,7 +353,7 @@ task:
       # ${CORE_DUMP_DIR}, they may not obey this. So, move core files to the
       # ${CORE_DUMP_DIR} directory.
       find build/ -type f -name '*.core' -exec mv '{}' ${CORE_DUMP_DIR} \;
-      src/tools/ci/cores_backtrace.sh ${OS_NAME} ${CORE_DUMP_DIR}
+      src/tools/ci/cores_backtrace.sh ${OS_NAME} ${CORE_DUMP_DIR} ${CORE_DUMP_EXECUTABLE_DIR}
 
 
 # configure feature flags, shared between the task running the linux tests and
index 546074152581474a7915132e1e3c0c6850681cc8..cb325f21156daf90c07b02d0e16c40bc5f6fc53e 100755 (executable)
@@ -1,12 +1,18 @@
 #! /bin/sh
 
-if [ $# -ne 2 ]; then
+os=$1
+directory=$2
+executable_directory=$3
+
+if [ "$os" != 'openbsd' ] && [ $# -ne 2 ]; then
     echo "cores_backtrace.sh <os> <directory>"
     exit 1
 fi
 
-os=$1
-directory=$2
+if [ "$os" = 'openbsd' ] && [ $# -ne 3 ]; then
+    echo "cores_backtrace.sh <os> <core_directory> <executable_directory>"
+    exit 1
+fi
 
 case $os in
     freebsd|linux|macos|netbsd|openbsd)
@@ -17,6 +23,10 @@ case $os in
     ;;
 esac
 
+if [ "$os" = 'openbsd' ]; then
+    export PATH="${executable_directory}:${PATH}"
+fi
+
 first=1
 for corefile in $(find "$directory" -type f) ; do
     if [ "$first" -eq 1 ]; then
@@ -26,8 +36,21 @@ for corefile in $(find "$directory" -type f) ; do
         echo -e '\n\n'
     fi
 
-    if [ "$os" = 'macos' ] || [ "$os" = 'openbsd' ]; then
+    if [ "$os" = 'macos' ]; then
         lldb -c $corefile --batch -o 'thread backtrace all' -o 'quit'
+    elif [ "$os" = 'openbsd' ]; then
+        # OpenBSD's ELF format doesn't include executable information, so we
+        # search for the executable manually in <executable_directory>.
+        filename=$(basename "$corefile")
+        base=$(echo "$filename" | sed 's/\.core.*$//')
+        binary=$(which "${base}")
+
+        if [ -z "$binary" ]; then
+            echo "executable ${base} not found in ${PATH}, running 'lldb' without debug information"
+            lldb -c "$corefile" --batch -o 'thread backtrace all' -o 'quit'
+        else
+            lldb "$binary" -c "$corefile" --batch -o 'thread backtrace all' -o 'quit'
+        fi
     else
         auxv=$(gdb --quiet --core ${corefile} --batch -ex 'info auxv' 2>/dev/null)
         if [ $? -ne 0 ]; then