Skip to content

Instantly share code, notes, and snippets.

@andrey-utkin
Created April 3, 2018 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrey-utkin/264e9e8e14008ab68ac0f500e3c90978 to your computer and use it in GitHub Desktop.
Save andrey-utkin/264e9e8e14008ab68ac0f500e3c90978 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Taken from http://dustymabe.com/2012/10/14/trace-function-calls-using-gdb/
# Make a function call trace using GDB. This is stupid, but it should work
if [ "$*" = "" ]; then
echo "usage: $0 [args]"
exit
fi
_CMDFILE=/tmp/`basename $0`.$$
_PROG=$1
shift
echo Writing GDB commands file
# Write the temporary GDB commands file
echo "set args $*" > $_CMDFILE
for i in `nm -f posix $_PROG | awk '$2 == "T" { print $1}'`; do
(echo break $i
echo command
echo silent
echo backtrace 1
echo continue
echo end
echo
) >> $_CMDFILE
done
echo run >> $_CMDFILE
# Now do the run
echo Starting GDB
gdb -quiet -command=$_CMDFILE $_PROG < /dev/null
# and clean up
echo GDB run finished
rm -f $_CMDFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment