Function call tracking tool using GDB

This commit is contained in:
Robert Bendun 2022-05-21 23:00:32 +02:00
parent 881b90506b
commit c488153805

36
etc/tools/log-function-calls.sh Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Inspired by https://dustymabe.com/2012/12/17/trace-function-calls-using-gdb-revisited/
set -e -o pipefail
if ! command -v gdb >/dev/null; then
echo "$(basename "$1"): error: GDB is required for this script to work" 1>&2
exit 1
fi
if [ ! -d src ]; then
echo "$(basename "$1"): error: Expected directory 'src' in working directory" 1>&2
exit 1
fi
tempfile=$(mktemp "${TMPDIR:-/tmp/}$(basename $0).XXXX")
echo "set confirm off" > $tempfile
for src in src/*.cc; do
echo "rbreak $src:.
command
silent
backtrace 1
continue
end" >> $tempfile
done
echo "run $@" >> $tempfile
set -x
make debug
gdb -quiet -batch -x "$tempfile" bin/musique
set +x
rm "$tempfile"