1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#!/usr/bin/env bash
set -o errexit
set -o pipefail
if ! which gdb >/dev/null; then
echo "gdb not found. Will not search for core files"
exit 0
fi
echo "Debugging core files"
cd build
shopt -s nullglob
for i in *.core; do
echo "${i:?}"
# find out which executable corresponds to the core dump
# file <core> produces a string like:
# ./core: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from './a.out'
binary_path="$(file "${i:?}" | awk '{print $NF}' | awk -F "'" '{print $2}')"
echo "core dump produced by ${binary_path:?}"
echo "backtrace full" | gdb -q "${binary_path:?}" "${i:?}"
done
cd ..
|