Hi,

Thank you for looking into this!

On Sat, 25 Oct 2025 at 00:41, Thomas Munro <[email protected]> wrote:
>
> On Sat, Oct 25, 2025 at 2:20 AM Nazir Bilal Yavuz <[email protected]> wrote:
> > Any feedback would be appreciated.
>
> +        filename=$(basename "$corefile")
> +        base=$(echo "$filename" | sed 's/\.core.*$//')
> +        binary=$(find "$executable_directory" -type f -name "$base"
> 2>/dev/null | head -n 1)
> +
> +        if [ -z "$binary" ]; then
> +            echo "${base} executable can not be found in
> ${executable_directory}"
> +            continue
> +        fi
> +
> +        lldb "$binary" -c "$corefile" --batch -o 'thread backtrace
> all' -o 'quit'
>
> s/can not/cannot/, I don't make the rules...
>
> Maybe if not found it should just run it the old way without the
> executable?  We don't really expect other programs to be dumped (well,
> sometimes we abort cp etc, something I plan to fix...), and they're
> probably stripped anyway, but I guess we might as well try to show as
> much information as we can if it happens?  Would it be better to set
> PATH to $executable_directory:$PATH and use "which"?

I agree with all of your points. All of them are addressed in the v2.

--
Regards,
Nazir Bilal Yavuz
Microsoft
From 15883579c07267340334ae22ccb2d12e68ee19aa Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <[email protected]>
Date: Fri, 24 Oct 2025 13:29:30 +0300
Subject: [PATCH v2] ci: Improve OpenBSD core dump backtrace handling

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.

Author: Nazir Bilal Yavuz <[email protected]>
Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://postgr.es/m/can55fz36r74tz8rksfueywlxgkdam3lu2fhm_zucsb6imd3...@mail.gmail.com
---
 .cirrus.tasks.yml               |  3 ++-
 src/tools/ci/cores_backtrace.sh | 31 +++++++++++++++++++++++++++----
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index eca9d62fc22..e91b4f1783f 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -322,6 +322,7 @@ task:
         OS_NAME: openbsd
         IMAGE_FAMILY: pg-ci-openbsd-postgres
         PKGCONFIG_PATH: '/usr/lib/pkgconfig:/usr/local/lib/pkgconfig'
+        CORE_DUMP_EXECUTABLE_DIR: $CIRRUS_WORKING_DIR/build/tmp_install/usr/local/pgsql/bin
 
         MESON_FEATURES: >-
           -Dbsd_auth=enabled
@@ -388,7 +389,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
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 54607415258..d0de7720790 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -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 "${base} executable cannot be found in ${executable_directory}, running 'lldb' without the ${base} executable"
+            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
-- 
2.51.0

Reply via email to