solenv/bin/gdb-core-bt.sh |   64 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 14 deletions(-)

New commits:
commit 5440262dd2fc58025702b7172cebe6b9f1c466ec
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Feb 26 16:04:32 2024 +0200
Commit:     Noel Grandin <noelgran...@gmail.com>
CommitDate: Thu Mar 27 15:10:16 2025 +0100

    Get at least some information out of coredumpctl
    
    This is not great, but it is a dramatic improvement over the current
    situation (getting nothing).
    
    Change-Id: Id8f9b7f0e87229e4d5aefba448c4f062aac3c204
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163945
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/solenv/bin/gdb-core-bt.sh b/solenv/bin/gdb-core-bt.sh
index a834018f5a5d..e90cd04ada41 100755
--- a/solenv/bin/gdb-core-bt.sh
+++ b/solenv/bin/gdb-core-bt.sh
@@ -36,24 +36,60 @@ then
         fi
     done
     if test -n "$WITH_COREDUMPCTL"; then
-        # Unfortunately `coredumpctl debug` only operates on the most recent 
core dump matching any
-        # given criteria, not on all core dumps matching those criteria; so 
get the PIDs of all core
-        # dumps matching the given COREDUMP_USER_UNIT (and for which a core 
dump is still present)
-        # first, and then iterate over them (though this introduces 
possibilities for some,
-        # hopefully unlikely and mostly harmless, races, like when core dumps 
disappear in between,
-        # or multiple matching core dumps have identical PIDs):
-        for i in $($COREDUMPCTL --json=short list 
COREDUMP_USER_UNIT="$LIBO_TEST_UNIT".scope | \
-                       $JQ -r 
'map(select(.corefile=="present"))|map(.pid)|join(" ")')
-        do
+        systemd_version=$(systemctl --version | head -1 | awk '{ print $2 }')
+        # We need systemd version >= 248 in order for coredumpctl to support 
--json and --debugger-arguments
+        if [ $systemd_version -ge 248 ]
+        then
+            # Unfortunately `coredumpctl debug` only operates on the most 
recent core dump matching any
+            # given criteria, not on all core dumps matching those criteria; 
so get the PIDs of all core
+            # dumps matching the given COREDUMP_USER_UNIT (and for which a 
core dump is still present)
+            # first, and then iterate over them (though this introduces 
possibilities for some,
+            # hopefully unlikely and mostly harmless, races, like when core 
dumps disappear in between,
+            # or multiple matching core dumps have identical PIDs):
+            for i in $($COREDUMPCTL --json=short list 
COREDUMP_USER_UNIT="$LIBO_TEST_UNIT".scope | \
+                           $JQ -r 
'map(select(.corefile=="present"))|map(.pid)|join(" ")')
+            for i in $($COREDUMPCTL -q -r -1 list | cut -f 2)
+            do
+                GDBCOMMANDFILE=$(mktemp)
+                printf 'info registers
thread apply all backtrace full
' >"$GDBCOMMANDFILE"
+                PYTHONWARNINGS=default $COREDUMPCTL debug \
+                    COREDUMP_USER_UNIT="$LIBO_TEST_UNIT".scope 
COREDUMP_PID="$i" \
+                    --debugger-arguments="-iex 'add-auto-load-safe-path 
${INSTDIR?}' \
+                        -x '$GDBCOMMANDFILE' --batch"
+                rm "$GDBCOMMANDFILE"
+                found=x
+            done
+        else
+            # NoelGrandin - so I can confirm 3 things:
+            # (1) virtually none of the jenkins boxes have coredumpctl new 
enough for the --json option.
+            # (2) virtually none of the jenkins boxes have coredumpctl new 
enough for the --debugger-arguments option
+            # (3) Around 50% of the time, coredumpctl will say it has no core 
files available,
+            #     even though we have just dumped core.
+            # So just do our best, and hope that we are analysing the right 
core file.
+            #
+            sleep 10s
+            $COREDUMPCTL -1 list
+            # copy core file out of systemd
+            TEMPCOREFILE=$(mktemp)
+            $COREDUMPCTL -1 -o $TEMPCOREFILE dump
+            # analyse core file with gdb
+            guess=$(file "$TEMPCOREFILE")
+            guess=${guess#* execfn: \'}
+            guess=${guess%%\'*}
+            if [ ! -x "$guess" ]; then guess=$EXECUTABLE; fi
+            printf '
One of our tests dumped core, and we are generating a backtrace from the more 
recent core we can extract from coredumpctl.'
+            printf '
'
+            printf '
>>>>>This might not be the right one.<<<<'
+            printf '
'
+            printf '
It looks like %s generated %s
Backtraces:
' "$guess" "$TEMPCOREFILE"
             GDBCOMMANDFILE=$(mktemp)
             printf 'info registers
thread apply all backtrace full
' >"$GDBCOMMANDFILE"
-            PYTHONWARNINGS=default $COREDUMPCTL debug \
-                COREDUMP_USER_UNIT="$LIBO_TEST_UNIT".scope COREDUMP_PID="$i" \
-                --debugger-arguments="-iex 'add-auto-load-safe-path 
${INSTDIR?}' \
-                    -x '$GDBCOMMANDFILE' --batch"
+            PYTHONWARNINGS=default gdb -iex "add-auto-load-safe-path 
${INSTDIR?}" \
+                -x "$GDBCOMMANDFILE" --batch "$guess" "$TEMPCOREFILE"
             rm "$GDBCOMMANDFILE"
+            rm "$TEMPCOREFILE"
             found=x
-        done
+        fi
     fi
     if [ -z "$found" -a "$EXITCODE" -ge 128 ]; then
         echo

Reply via email to