Last active
December 16, 2015 19:18
-
-
Save icholy/5483670 to your computer and use it in GitHub Desktop.
Shell script to simplify setting GDB breakpoints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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