Re: [PATCH] Make running git under other debugger-like programs easy
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Apr 5, 2018, 19:57 UTC
- Message-ID
- <nycvar.QRO.7.76.6.1804052144310.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz>
- In-Reply-To
- <20180405174935.598-1-newren@gmail.com>
Hi Elijah,
On Thu, 5 Apr 2018, Elijah Newren wrote:
Show 9 quoted lines
> This allows us to run git, when using the script from bin-wrappers, under > other programs. A few examples: > GIT_WRAPPER=nemiver git $ARGS > GIT_WRAPPER="valgrind --tool=memcheck --track-origins=yes" git $ARGS > > Yes, we already have GIT_TEST_GDB (which could potentially be replaced > with GIT_WRAPPER="gdb --args"), and a bunch of options for running > a testcase or multiple testcases under valgrind, but I find the extra > flexibility useful.
It would be even more useful if it could be made to work interactively, too, by removing those redirections. The `debug` function does this thusly:
debug () {
GIT_TEST_GDB=1 "$@" <&6 >&5 2>&7
}I wonder whether a better approach would be to add an optional argument to that `debug` function (which is intended to have `git` as first argument, anyway, or at least a command/function that does not start with a dash):
debug_aux () {
shift
"$@" <&6 >&5 2>&7
}debug () {
case "$1" in
-d)
shift &&
GIT_TEST_GDB="$1" debug_aux "$@"
;;
--debugger=*)
GIT_TEST_GDB="${1#*=}" debug_aux "$@"
;;
*)
GIT_TEST_GDB=1 "$@" <&6 >&5 2>&7
;;
esac
}... and then in wrap-for-bin.sh, we would replace the last lines
if test -n "$GIT_TEST_GDB"
then
unset GIT_TEST_GDB
exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
else
exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
fiby
case "$GIT_TEST_GDB" in
'')
exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
;;
1)
unset GIT_TEST_GDB
exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
;;
*)
GIT_TEST_GDB_$$="$GIT_TEST_GDB"
unset GIT_TEST_GDB
exec $GIT_TEST_GDB_$$ "${GIT_EXEC_PATH}/@@PROG@@" "$@"
;;
esacor some such.
Then your magic "GIT_WRAPPER" invocation would become a bit more explicit:
debug --debugger=nemiver git $ARGS
debug -d "valgrind --tool=memcheck --track-origins=yes" git $ARGS(In any case, "GIT_WRAPPER" is probably a name in want of being renamed.)
Ciao, Dscho