Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active December 16, 2015 19:18
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save icholy/5483670 to your computer and use it in GitHub Desktop.
Save icholy/5483670 to your computer and use it in GitHub Desktop.
Shell script to simplify setting GDB breakpoints
# Demo http://ascii.io/a/3019
# build
gdbb () {
# build with debug flags
go build -gcflags "-N -l" -o out
# make sure the build didn't fail
if [ $? != 0 ]; then return; fi
# extract debugger comments
find $(pwd) -name "*.go" | grep -v "_test.go\$" | xargs awk '/\/\/debugger/ { print "break " FILENAME ":" FNR; }' > .breakpoints
# break on main if no breakpoints were found
if [ ! -s .breakpoints ]; then echo "break main.main" > .breakpoints; fi
# launch gdb
gdb -x .breakpoints -ex run --args out "$@"
# clean up
rm .breakpoints out
}
# test
gdbbtest () {
# build with debug flags
go test -c -gcflags "-N -l" "$@"
# make sure the build didn't fail
if [ $? != 0 ]; then return; fi
# extract debugger comments
find $(pwd) -name "*.go" | xargs awk '/\/\/debugger/ { print "break " FILENAME ":" FNR; }' > .breakpoints
# if breakpoints were found, run on start
if [ -s .breakpoints ]; then
gdb -x .breakpoints -ex run *.test
else
gdb *.test
fi
# clean up
rm .breakpoints *.test
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment