git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] Make running git under other debugger-like programs easy

From
Elijah Newren <newren@gmail.com>
Date
Apr 9, 2018, 18:51 UTC
Message-ID
<20180409185136.4880-1-newren@gmail.com>
In-Reply-To
<20180405174935.598-1-newren@gmail.com>

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>
---
 t/test-lib-functions.sh | 24 ++++++++++++++++++++----
 wrap-for-bin.sh         | 19 +++++++++++++------
 2 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 1701fe2a06..0591d9a7f8 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -145,12 +145,28 @@ test_pause () {
 	"$SHELL_PATH" <&6 >&5 2>&7
 }
 
-# Wrap git in gdb. Adding this to a command can make it easier to
-# understand what is going on in a failing test.
+# Wrap git with a debugger. Adding this to a command can make it easier
+# to understand what is going on in a failing test.
 #
-# Example: "debug git checkout master".
+# Examples:
+#     debug git checkout master
+#     debug --debugger=nemiver git $ARGS
+#     debug -d "valgrind --tool=memcheck --track-origins=yes" git $ARGS
 debug () {
-	 GIT_TEST_GDB=1 "$@" <&6 >&5 2>&7
+	case "$1" in
+	-d)
+		DBG_FLAGS="$2" &&
+		shift 2
+		;;
+	--debugger=*)
+		DBG_FLAGS="${1#*=}" &&
+		shift 1
+		;;
+	*)
+		DBG_FLAGS=1
+		;;
+	esac &&
+	GIT_DEBUGGER="${DBG_FLAGS}" "$@" <&6 >&5 2>&7
 }
 
 # Call test_commit with the arguments
diff --git a/wrap-for-bin.sh b/wrap-for-bin.sh
index 22b6e4948f..376c056842 100644
--- a/wrap-for-bin.sh
+++ b/wrap-for-bin.sh
@@ -20,10 +20,17 @@ PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
 
 export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
 
-if test -n "$GIT_TEST_GDB"
-then
-	unset GIT_TEST_GDB
-	exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
-else
+case "$GIT_DEBUGGER" in
+'')
 	exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"
-fi
+	;;
+1)
+	unset GIT_DEBUGGER
+	exec gdb --args "${GIT_EXEC_PATH}/@@PROG@@" "$@"
+	;;
+*)
+	GIT_DEBUGGER_ARGS="$GIT_DEBUGGER"
+	unset GIT_DEBUGGER
+	exec ${GIT_DEBUGGER_ARGS} "${GIT_EXEC_PATH}/@@PROG@@" "$@"
+	;;
+esac
-- 
2.15.0.1.gcd9d12fc4a.dirty
Previous: Elijah NewrenNext: Johannes Schindelin
Message 6 of 12 in “Make running git under other debugger-like programs easy”
  1. Make running git under other debugger-like programs easyElijah Newren, Apr 5, 2018
  2. Johannes SchindelinApr 5, 2018
  3. Elijah NewrenApr 5, 2018
  4. Johannes SchindelinApr 6, 2018
  5. Elijah NewrenApr 6, 2018
  6. Make running git under other debugger-like programs easyElijah Newren, Apr 9, 2018
  7. Johannes SchindelinApr 9, 2018
  8. Elijah NewrenApr 10, 2018
  9. Johannes SchindelinApr 10, 2018
  10. Make running git under other debugger-like programs easyElijah Newren, Apr 24, 2018
  11. Johannes SchindelinApr 25, 2018
  12. Junio C HamanoApr 26, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.