Bump version to 24.04.3.4
[LibreOffice.git] / solenv / bin / gdb-core-bt.sh
blob0276a70f4f0c7bfa284aebc6954cfde22d4b2f61
1 #!/bin/sh
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 EXECUTABLE=${1}
13 COREDIR=${2}
14 EXITCODE=${3}
16 if test -n "$(which gdb)"
17 then
18 found=
19 for COREFILE in "$COREDIR"/core*
21 if [ -f "$COREFILE" ]
22 then
23 guess=$(file "$COREFILE")
24 guess=${guess#* execfn: \'}
25 guess=${guess%%\'*}
26 if [ ! -x "$guess" ]; then guess=$EXECUTABLE; fi
27 printf '\nIt looks like %s generated %s\nBacktraces:\n' \
28 "$guess" "$COREFILE"
29 GDBCOMMANDFILE=$(mktemp)
30 printf "info registers\nthread apply all backtrace full\n" \
31 >"$GDBCOMMANDFILE"
32 PYTHONWARNINGS=default gdb -iex "add-auto-load-safe-path ${INSTDIR?}" \
33 -x "$GDBCOMMANDFILE" --batch "$guess" "$COREFILE" && found=x
34 rm "$GDBCOMMANDFILE"
35 echo
37 done
38 if test -n "$WITH_COREDUMPCTL"; then
39 # Unfortunately `coredumpctl debug` only operates on the most recent core dump matching any
40 # given criteria, not on all core dumps matching those criteria; so get the PIDs of all core
41 # dumps matching the given COREDUMP_USER_UNIT (and for which a core dump is still present)
42 # first, and then iterate over them (though this introduces possibilities for some,
43 # hopefully unlikely and mostly harmless, races, like when core dumps disappear in between,
44 # or multiple matching core dumps have identical PIDs):
45 for i in $($COREDUMPCTL --json=short list COREDUMP_USER_UNIT="$LIBO_TEST_UNIT".scope | \
46 $JQ -r 'map(select(.corefile=="present"))|map(.pid)|join(" ")')
48 GDBCOMMANDFILE=$(mktemp)
49 printf 'info registers\nthread apply all backtrace full\n' >"$GDBCOMMANDFILE"
50 PYTHONWARNINGS=default $COREDUMPCTL debug \
51 COREDUMP_USER_UNIT="$LIBO_TEST_UNIT".scope COREDUMP_PID="$i" \
52 --debugger-arguments="-iex 'add-auto-load-safe-path ${INSTDIR?}' \
53 -x '$GDBCOMMANDFILE' --batch"
54 rm "$GDBCOMMANDFILE"
55 found=x
56 done
58 if [ -z "$found" -a "$EXITCODE" -ge 128 ]; then
59 echo
60 echo "No core file identified in directory ${COREDIR}"
61 echo "To show backtraces for crashes during test execution,"
62 echo "enable core files with:"
63 echo
64 echo " ulimit -c unlimited"
65 echo
66 exit 1
68 else
69 echo "You need gdb in your path to show backtraces"
70 exit 1