Make running git under other debugger-like programs easy

This allows us to run git, when using the script from bin-wrappers, under other programs. A few examples for usage within testsuite scripts: debug git checkout master debug --debugger=nemiver git $ARGS debug -d "valgrind --tool-memcheck --track-origins=yes" git $ARGS Or, if someone has bin-wrappers/ in their $PATH and is executing git outside the testsuite: GIT_DEBUGGER="gdb --args" git $ARGS GIT_DEBUGGER=nemiver git $ARGS GIT_DEBUGGER="valgrind --tool=memcheck --track-origins=yes" git $ARGS There is also a handy shortcut of GIT_DEBUGGER=1 meaning the same as GIT_DEBUGGER="gdb --args" Original-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 24, 2018 at 16:46 UTC 842436466aa5d9f1e5f1a09d41d22d902006219c
2 files changed +33 -10
t/test-lib-functions.sh
+20 -4
@@ -145,12 +145,28 @@ test_pause () {
145 "$SHELL_PATH" <&6 >&5 2>&7
146 }
147
148 -# Wrap git in gdb. Adding this to a command can make it easier to
149 -# understand what is going on in a failing test.
148 +# Wrap git with a debugger. Adding this to a command can make it easier
149 +# to understand what is going on in a failing test.
150 #
151 -# Example: "debug git checkout master".
151 +# Examples:
152 +# debug git checkout master
153 +# debug --debugger=nemiver git $ARGS
154 +# debug -d "valgrind --tool=memcheck --track-origins=yes" git $ARGS
155 debug () {
153 - GIT_TEST_GDB=1 "$@" <&6 >&5 2>&7
156 + case "$1" in
157 + -d)
158 + GIT_DEBUGGER="$2" &&
159 + shift 2
160 + ;;
161 + --debugger=*)
162 + GIT_DEBUGGER="${1#*=}" &&
163 + shift 1
164 + ;;
165 + *)
166 + GIT_DEBUGGER=1
167 + ;;
168 + esac &&
169 + GIT_DEBUGGER="${GIT_DEBUGGER}" "$@" <&6 >&5 2>&7
170 }
171
172 # Call test_commit with the arguments
wrap-for-bin.sh
+13 -6
@@ -20,10 +20,17 @@ PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
20
21 export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
22
23 -if test -n "$GIT_TEST_GDB"
24 -then
25 - unset GIT_TEST_GDB
26 - exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
27 -else
23 +case "$GIT_DEBUGGER" in
24 +'')
25 exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
29 -fi
26 + ;;
27 +1)
28 + unset GIT_DEBUGGER
29 + exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
30 + ;;
31 +*)
32 + GIT_DEBUGGER_ARGS="$GIT_DEBUGGER"
33 + unset GIT_DEBUGGER
34 + exec ${GIT_DEBUGGER_ARGS} "${GIT_EXEC_PATH}/@@PROG@@" "$@"
35 + ;;
36 +esac