{"thread":{"id":"48228","subject":"[PATCH] Make running git under other debugger-like programs easy","startedAt":"2018-04-05T17:49:50Z","lastAt":"2018-04-26T01:56:10Z","messageCount":12,"participants":["Elijah Newren","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"343884","messageId":"20180405174935.598-1-newren@gmail.com","threadId":"48228","inReplyTo":null,"subject":"[PATCH] Make running git under other debugger-like programs easy","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-04-05T17:49:35Z","receivedAt":"2018-04-05T17:49:50Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"This allows us to run git, when using the script from bin-wrappers, under\nother programs.  A few examples:\n   GIT_WRAPPER=nemiver git $ARGS\n   GIT_WRAPPER=\"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n\nYes, we already have GIT_TEST_GDB (which could potentially be replaced\nwith GIT_WRAPPER=\"gdb --args\"), and a bunch of options for running\na testcase or multiple testcases under valgrind, but I find the extra\nflexibility useful.\n\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\n wrap-for-bin.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/wrap-for-bin.sh b/wrap-for-bin.sh\nindex 5842408817..1b34d44193 100644\n--- a/wrap-for-bin.sh\n+++ b/wrap-for-bin.sh\n@@ -25,5 +25,5 @@ then\n \tunset GIT_TEST_GDB\n \texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n else\n-\texec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n+\texec ${GIT_WRAPPER} \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n fi\n-- \n2.17.0.7.g0b50f94d69\n\n"},{"id":"343895","messageId":"nycvar.QRO.7.76.6.1804052144310.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","threadId":"48228","inReplyTo":"20180405174935.598-1-newren@gmail.com","subject":"Re: [PATCH] Make running git under other debugger-like programs easy","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-04-05T19:57:51Z","receivedAt":"2018-04-05T19:57:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Elijah,\n\nOn Thu, 5 Apr 2018, Elijah Newren wrote:\n\n> This allows us to run git, when using the script from bin-wrappers, under\n> other programs.  A few examples:\n>    GIT_WRAPPER=nemiver git $ARGS\n>    GIT_WRAPPER=\"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n> \n> Yes, we already have GIT_TEST_GDB (which could potentially be replaced\n> with GIT_WRAPPER=\"gdb --args\"), and a bunch of options for running\n> a testcase or multiple testcases under valgrind, but I find the extra\n> flexibility useful.\n\nIt would be even more useful if it could be made to work interactively,\ntoo, by removing those redirections. The `debug` function does this\nthusly:\n\ndebug () {\n         GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n}\n\nI wonder whether a better approach would be to add an optional argument to\nthat `debug` function (which is intended to have `git` as first argument,\nanyway, or at least a command/function that does not start with a dash):\n\ndebug_aux () {\n\tshift\n\t\"$@\" <&6 >&5 2>&7\n}\n\ndebug () {\n\tcase \"$1\" in\n\t-d)\n\t\tshift &&\n\t\tGIT_TEST_GDB=\"$1\" debug_aux \"$@\"\n\t\t;;\n\t--debugger=*)\n\t\tGIT_TEST_GDB=\"${1#*=}\" debug_aux \"$@\"\n\t\t;;\n\t*)\n\t\tGIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n\t\t;;\n\tesac\n}\n\n... and then in wrap-for-bin.sh, we would replace the last lines\n\nif test -n \"$GIT_TEST_GDB\"\nthen\n\tunset GIT_TEST_GDB\n\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\nelse\n\texec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\nfi\n\nby\n\ncase \"$GIT_TEST_GDB\" in\n'')\n\texec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n\t;;\n1)\n\tunset GIT_TEST_GDB\n\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n\t;;\n*)\n\tGIT_TEST_GDB_$$=\"$GIT_TEST_GDB\"\n\tunset GIT_TEST_GDB\n\texec $GIT_TEST_GDB_$$ \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n\t;;\nesac\n\nor some such.\n\nThen your magic \"GIT_WRAPPER\" invocation would become a bit more explicit:\n\n    debug --debugger=nemiver git $ARGS\n    debug -d \"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n\n(In any case, \"GIT_WRAPPER\" is probably a name in want of being renamed.)\n\nCiao,\nDscho\n"},{"id":"343897","messageId":"CABPp-BHhdxuV9a_4OfgaRu89Kx2039OLeS1vW-KdzpLxb-ZF3g@mail.gmail.com","threadId":"48228","inReplyTo":"nycvar.QRO.7.76.6.1804052144310.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","subject":"Re: [PATCH] Make running git under other debugger-like programs easy","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-04-05T21:16:19Z","receivedAt":"2018-04-05T21:16:30Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Hi Johannes,\n\nOn Thu, Apr 5, 2018 at 12:57 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n\n> I wonder whether a better approach would be to add an optional argument to\n> that `debug` function (which is intended to have `git` as first argument,\n> anyway, or at least a command/function that does not start with a dash):\n>\n> debug_aux () {\n>         shift\n>         \"$@\" <&6 >&5 2>&7\n> }\n>\n> debug () {\n>         case \"$1\" in\n>         -d)\n>                 shift &&\n>                 GIT_TEST_GDB=\"$1\" debug_aux \"$@\"\n>                 ;;\n>         --debugger=*)\n>                 GIT_TEST_GDB=\"${1#*=}\" debug_aux \"$@\"\n>                 ;;\n>         *)\n>                 GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n>                 ;;\n>         esac\n> }\n>\n> ... and then in wrap-for-bin.sh, we would replace the last lines\n>\n> if test -n \"$GIT_TEST_GDB\"\n> then\n>         unset GIT_TEST_GDB\n>         exec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> else\n>         exec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> fi\n>\n> by\n>\n> case \"$GIT_TEST_GDB\" in\n> '')\n>         exec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n>         ;;\n> 1)\n>         unset GIT_TEST_GDB\n>         exec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n>         ;;\n> *)\n>         GIT_TEST_GDB_$$=\"$GIT_TEST_GDB\"\n>         unset GIT_TEST_GDB\n>         exec $GIT_TEST_GDB_$$ \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n>         ;;\n> esac\n>\n> or some such.\n\nThat all looks great to me.  But at this point, it seems like it's a\nfull rewrite and your patch to submit (which I'd be happy to endorse\nin lieu of my own)...or do you want me to submit with you as author\nand me as committer?\n\nAlso, a side question: if we go this route, do we want to rename\nGIT_TEST_GDB to reflect its expanded usage?\n\n> Then your magic \"GIT_WRAPPER\" invocation would become a bit more explicit:\n>\n>     debug --debugger=nemiver git $ARGS\n>     debug -d \"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n\nNo, for most (60-80%?) of my invocations, I wouldn't be able to use\nthe debug function; only a minority of my uses are from within the\ntestsuite.  The rest are from the command line (I have\ngit/bin-wrappers/ in my $PATH), so the above suggestions would mean\nthat my invocation would become:\n\nGIT_TEST_GDB=\"nemiver\" git $ARGS\nGIT_TEST_GDB=\"valgrind --tool-memcheck --track-origins=yes\" git $ARGS\n\n> (In any case, \"GIT_WRAPPER\" is probably a name in want of being renamed.)\n\nWell, with your suggestion, it'd just be whatever that environment\nvariable is named.  I'm perfectly happy with something other than\nGIT_WRAPPER (or GIT_TEST_GDB).  I'm not so good at coming up with such\nmyself, but maybe something like GIT_DEBUGGER or GIT_DEBUG_WITH?\n\nThanks,\nElijah\n"},{"id":"343950","messageId":"nycvar.QRO.7.76.6.1804061233330.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","threadId":"48228","inReplyTo":"CABPp-BHhdxuV9a_4OfgaRu89Kx2039OLeS1vW-KdzpLxb-ZF3g@mail.gmail.com","subject":"Re: [PATCH] Make running git under other debugger-like programs easy","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-04-06T10:38:29Z","receivedAt":"2018-04-06T10:38:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Elijah,\n\nOn Thu, 5 Apr 2018, Elijah Newren wrote:\n\n> On Thu, Apr 5, 2018 at 12:57 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> \n> > I wonder whether a better approach would be to add an optional argument to\n> > that `debug` function (which is intended to have `git` as first argument,\n> > anyway, or at least a command/function that does not start with a dash):\n> >\n> > debug_aux () {\n> >         shift\n> >         \"$@\" <&6 >&5 2>&7\n> > }\n> >\n> > debug () {\n> >         case \"$1\" in\n> >         -d)\n> >                 shift &&\n> >                 GIT_TEST_GDB=\"$1\" debug_aux \"$@\"\n> >                 ;;\n> >         --debugger=*)\n> >                 GIT_TEST_GDB=\"${1#*=}\" debug_aux \"$@\"\n> >                 ;;\n> >         *)\n> >                 GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n> >                 ;;\n> >         esac\n> > }\n> >\n> > ... and then in wrap-for-bin.sh, we would replace the last lines\n> >\n> > if test -n \"$GIT_TEST_GDB\"\n> > then\n> >         unset GIT_TEST_GDB\n> >         exec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> > else\n> >         exec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> > fi\n> >\n> > by\n> >\n> > case \"$GIT_TEST_GDB\" in\n> > '')\n> >         exec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> >         ;;\n> > 1)\n> >         unset GIT_TEST_GDB\n> >         exec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> >         ;;\n> > *)\n> >         GIT_TEST_GDB_$$=\"$GIT_TEST_GDB\"\n> >         unset GIT_TEST_GDB\n> >         exec $GIT_TEST_GDB_$$ \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> >         ;;\n> > esac\n> >\n> > or some such.\n> \n> That all looks great to me.  But at this point, it seems like it's a\n> full rewrite and your patch to submit (which I'd be happy to endorse\n> in lieu of my own)...\n\n:-)\n\n> or do you want me to submit with you as author and me as committer?\n\nThat would be my preference. I have not even tested what I wrote above...\n\n> Also, a side question: if we go this route, do we want to rename\n> GIT_TEST_GDB to reflect its expanded usage?\n\nSure. Probably GIT_TEST_DEBUGGER? Or GIT_TEST_DBG? Or GIT_TEST_DEBUG?\n\n> > Then your magic \"GIT_WRAPPER\" invocation would become a bit more explicit:\n> >\n> >     debug --debugger=nemiver git $ARGS\n> >     debug -d \"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n> \n> No, for most (60-80%?) of my invocations, I wouldn't be able to use\n> the debug function; only a minority of my uses are from within the\n> testsuite.  The rest are from the command line (I have\n> git/bin-wrappers/ in my $PATH),\n\nOy vey. bin-wrappers in your PATH? That's even worse than what I did in\nthe first two years of developing Git: I always ran `git` in-place.\nHowever, I was bitten by a couple of bugs introduced while developing that\nmade it hard to recover (if I don't have a functional Git, I cannot use it\nto go back to a working version, can I?). How do *you* deal with these\nthings?\n\n> so the above suggestions would mean that my invocation would become:\n> \n> GIT_TEST_GDB=\"nemiver\" git $ARGS\n> GIT_TEST_GDB=\"valgrind --tool-memcheck --track-origins=yes\" git $ARGS\n\nRight.\n\n> > (In any case, \"GIT_WRAPPER\" is probably a name in want of being renamed.)\n> \n> Well, with your suggestion, it'd just be whatever that environment\n> variable is named.  I'm perfectly happy with something other than\n> GIT_WRAPPER (or GIT_TEST_GDB).  I'm not so good at coming up with such\n> myself, but maybe something like GIT_DEBUGGER or GIT_DEBUG_WITH?\n\nI like both. Pick whatever you like, as long as it starts with `GIT_` and\nis descriptive enough. Even `GIT_LAUNCH_THROUGH` would work, but\n`GIT_DEBUGGER` seems to be the shortest that still makes sense.\n\nCiao,\nDscho\n"},{"id":"344022","messageId":"CABPp-BE0ERL0ueX_sqUwDvt_cQ8QYkzWruvSWZiFGNawR3vCeg@mail.gmail.com","threadId":"48228","inReplyTo":"nycvar.QRO.7.76.6.1804061233330.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","subject":"Re: [PATCH] Make running git under other debugger-like programs easy","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-04-06T22:36:15Z","receivedAt":"2018-04-06T22:36:22Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"Hi Dscho,\n\nOn Fri, Apr 6, 2018 at 3:38 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> On Thu, 5 Apr 2018, Elijah Newren wrote:\n>> On Thu, Apr 5, 2018 at 12:57 PM, Johannes Schindelin\n>> <Johannes.Schindelin@gmx.de> wrote:\n\n<snip>\n\n>> That all looks great to me.  But at this point, it seems like it's a\n>> full rewrite and your patch to submit (which I'd be happy to endorse\n>> in lieu of my own)...\n>\n> :-)\n>\n>> or do you want me to submit with you as author and me as committer?\n>\n> That would be my preference. I have not even tested what I wrote above...\n\nSure, will do.\n\n>> Also, a side question: if we go this route, do we want to rename\n>> GIT_TEST_GDB to reflect its expanded usage?\n>\n> Sure. Probably GIT_TEST_DEBUGGER? Or GIT_TEST_DBG? Or GIT_TEST_DEBUG?\n>\n>> > Then your magic \"GIT_WRAPPER\" invocation would become a bit more explicit:\n>> >\n>> >     debug --debugger=nemiver git $ARGS\n>> >     debug -d \"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n>>\n>> No, for most (60-80%?) of my invocations, I wouldn't be able to use\n>> the debug function; only a minority of my uses are from within the\n>> testsuite.  The rest are from the command line (I have\n>> git/bin-wrappers/ in my $PATH),\n>\n> Oy vey. bin-wrappers in your PATH? That's even worse than what I did in\n> the first two years of developing Git: I always ran `git` in-place.\n> However, I was bitten by a couple of bugs introduced while developing that\n> made it hard to recover (if I don't have a functional Git, I cannot use it\n> to go back to a working version, can I?). How do *you* deal with these\n> things?\n\nI also have an older system git in /usr/bin; if things go sideways, I\njust explicitly use '/usr/bin/git' instead of 'git'.\n\n>> > (In any case, \"GIT_WRAPPER\" is probably a name in want of being renamed.)\n>>\n>> Well, with your suggestion, it'd just be whatever that environment\n>> variable is named.  I'm perfectly happy with something other than\n>> GIT_WRAPPER (or GIT_TEST_GDB).  I'm not so good at coming up with such\n>> myself, but maybe something like GIT_DEBUGGER or GIT_DEBUG_WITH?\n>\n> I like both. Pick whatever you like, as long as it starts with `GIT_` and\n> is descriptive enough. Even `GIT_LAUNCH_THROUGH` would work, but\n> `GIT_DEBUGGER` seems to be the shortest that still makes sense.\n\nCool, GIT_DEBUGGER sounds good to me, I'll just proceed with it.\n"},{"id":"344224","messageId":"20180409185136.4880-1-newren@gmail.com","threadId":"48228","inReplyTo":"20180405174935.598-1-newren@gmail.com","subject":"[PATCH v2] Make running git under other debugger-like programs easy","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-04-09T18:51:36Z","receivedAt":"2018-04-09T18:52:14Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"This allows us to run git, when using the script from bin-wrappers, under\nother programs.  A few examples for usage within testsuite scripts:\n\n   debug git checkout master\n   debug --debugger=nemiver git $ARGS\n   debug -d \"valgrind --tool-memcheck --track-origins=yes\" git $ARGS\n\nOr, if someone has bin-wrappers/ in their $PATH and is executing git\noutside the testsuite:\n\n   GIT_DEBUGGER=\"gdb --args\" git $ARGS\n   GIT_DEBUGGER=nemiver git $ARGS\n   GIT_DEBUGGER=\"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n\nThere is also a handy shortcut of GIT_DEBUGGER=1 meaning the same as\nGIT_DEBUGGER=\"gdb --args\"\n\nOriginal-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\n t/test-lib-functions.sh | 24 ++++++++++++++++++++----\n wrap-for-bin.sh         | 19 +++++++++++++------\n 2 files changed, 33 insertions(+), 10 deletions(-)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 1701fe2a06..0591d9a7f8 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -145,12 +145,28 @@ test_pause () {\n \t\"$SHELL_PATH\" <&6 >&5 2>&7\n }\n \n-# Wrap git in gdb. Adding this to a command can make it easier to\n-# understand what is going on in a failing test.\n+# Wrap git with a debugger. Adding this to a command can make it easier\n+# to understand what is going on in a failing test.\n #\n-# Example: \"debug git checkout master\".\n+# Examples:\n+#     debug git checkout master\n+#     debug --debugger=nemiver git $ARGS\n+#     debug -d \"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n debug () {\n-\t GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n+\tcase \"$1\" in\n+\t-d)\n+\t\tDBG_FLAGS=\"$2\" &&\n+\t\tshift 2\n+\t\t;;\n+\t--debugger=*)\n+\t\tDBG_FLAGS=\"${1#*=}\" &&\n+\t\tshift 1\n+\t\t;;\n+\t*)\n+\t\tDBG_FLAGS=1\n+\t\t;;\n+\tesac &&\n+\tGIT_DEBUGGER=\"${DBG_FLAGS}\" \"$@\" <&6 >&5 2>&7\n }\n \n # Call test_commit with the arguments\ndiff --git a/wrap-for-bin.sh b/wrap-for-bin.sh\nindex 22b6e4948f..376c056842 100644\n--- a/wrap-for-bin.sh\n+++ b/wrap-for-bin.sh\n@@ -20,10 +20,17 @@ PATH='@@BUILD_DIR@@/bin-wrappers:'\"$PATH\"\n \n export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR\n \n-if test -n \"$GIT_TEST_GDB\"\n-then\n-\tunset GIT_TEST_GDB\n-\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n-else\n+case \"$GIT_DEBUGGER\" in\n+'')\n \texec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n-fi\n+\t;;\n+1)\n+\tunset GIT_DEBUGGER\n+\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n+\t;;\n+*)\n+\tGIT_DEBUGGER_ARGS=\"$GIT_DEBUGGER\"\n+\tunset GIT_DEBUGGER\n+\texec ${GIT_DEBUGGER_ARGS} \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n+\t;;\n+esac\n-- \n2.15.0.1.gcd9d12fc4a.dirty\n\n"},{"id":"344246","messageId":"nycvar.QRO.7.76.6.1804092316280.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","threadId":"48228","inReplyTo":"20180409185136.4880-1-newren@gmail.com","subject":"Re: [PATCH v2] Make running git under other debugger-like programs easy","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-04-09T21:19:52Z","receivedAt":"2018-04-09T21:20:12Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Elijah,\n\nOn Mon, 9 Apr 2018, Elijah Newren wrote:\n\n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index 1701fe2a06..0591d9a7f8 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -145,12 +145,28 @@ test_pause () {\n>  \t\"$SHELL_PATH\" <&6 >&5 2>&7\n>  }\n>  \n> -# Wrap git in gdb. Adding this to a command can make it easier to\n> -# understand what is going on in a failing test.\n> +# Wrap git with a debugger. Adding this to a command can make it easier\n> +# to understand what is going on in a failing test.\n>  #\n> -# Example: \"debug git checkout master\".\n> +# Examples:\n> +#     debug git checkout master\n> +#     debug --debugger=nemiver git $ARGS\n> +#     debug -d \"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n>  debug () {\n> -\t GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n> +\tcase \"$1\" in\n> +\t-d)\n> +\t\tDBG_FLAGS=\"$2\" &&\n\nMaybe we can find a way that does not require setting a variable other\nthan GIT_DEBUGGER? After all, DBG_FLAGS will be visible to the script\ncalling `debug`...\n\n> +\t\tshift 2\n> +\t\t;;\n> +\t--debugger=*)\n> +\t\tDBG_FLAGS=\"${1#*=}\" &&\n> +\t\tshift 1\n> +\t\t;;\n> +\t*)\n> +\t\tDBG_FLAGS=1\n> +\t\t;;\n> +\tesac &&\n> +\tGIT_DEBUGGER=\"${DBG_FLAGS}\" \"$@\" <&6 >&5 2>&7\n>  }\n>  \n>  # Call test_commit with the arguments\n> diff --git a/wrap-for-bin.sh b/wrap-for-bin.sh\n> index 22b6e4948f..376c056842 100644\n> --- a/wrap-for-bin.sh\n> +++ b/wrap-for-bin.sh\n> @@ -20,10 +20,17 @@ PATH='@@BUILD_DIR@@/bin-wrappers:'\"$PATH\"\n>  \n>  export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR\n>  \n> -if test -n \"$GIT_TEST_GDB\"\n> -then\n> -\tunset GIT_TEST_GDB\n> -\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> -else\n> +case \"$GIT_DEBUGGER\" in\n> +'')\n>  \texec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> -fi\n> +\t;;\n> +1)\n> +\tunset GIT_DEBUGGER\n> +\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> +\t;;\n> +*)\n> +\tGIT_DEBUGGER_ARGS=\"$GIT_DEBUGGER\"\n> +\tunset GIT_DEBUGGER\n> +\texec ${GIT_DEBUGGER_ARGS} \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n\nIt may not be a big deal, bug GIT_DEBUGGER_ARGS (if it was exported e.g.\nby the user calling the script) is now visible by the called process... (I\nthought I had tried my best to avoid such a leaking variable in my\npatch...)\n\nThanks,\nDscho\n"},{"id":"344285","messageId":"CABPp-BF4x-ppjptq1TBj+VicvGeWGbfj4e3f5ne_13AEKmvSQQ@mail.gmail.com","threadId":"48228","inReplyTo":"nycvar.QRO.7.76.6.1804092316280.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","subject":"Re: [PATCH v2] Make running git under other debugger-like programs easy","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-04-10T00:48:33Z","receivedAt":"2018-04-10T00:48:40Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"[Re-sending, making sure the annoying rich text mode isn't turned on\nin gmail...]\n\nHi Dscho,\n\nOn Mon, Apr 9, 2018 at 2:19 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi Elijah,\n>\n> On Mon, 9 Apr 2018, Elijah Newren wrote:\n>\n>>  debug () {\n>> -      GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n>> +     case \"$1\" in\n>> +     -d)\n>> +             DBG_FLAGS=\"$2\" &&\n>\n> Maybe we can find a way that does not require setting a variable other\n> than GIT_DEBUGGER? After all, DBG_FLAGS will be visible to the script\n> calling `debug`...\n\nI guess we could instead do a\n   export GIT_DEBUGGER=\"$2\"\nhere.  Short of explicitly using 'export', I think we'd need another\nenvironment variable.\n\nI would have stuck with your original suggestion, except that by running:\n    GIT_DEBUGGER=\"$1\" debug_aux \"$@\"\nGIT_DEBUGGER would be set within the debug_aux function and would NOT\nbe set once bin-wrappers/git was called, making git not run under the\ndebugger as desired.\n\n>> +*)\n>> +     GIT_DEBUGGER_ARGS=\"$GIT_DEBUGGER\"\n>> +     unset GIT_DEBUGGER\n>> +     exec ${GIT_DEBUGGER_ARGS} \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n>\n> It may not be a big deal, bug GIT_DEBUGGER_ARGS (if it was exported e.g.\n> by the user calling the script) is now visible by the called process... (I\n> thought I had tried my best to avoid such a leaking variable in my\n> patch...)\n\nYou had a separate, per-process variable:\nGIT_DEBUGGER_$$=\"$GIT_DEBUGGER\"\n\nThe problem with that line is that the $$ apparently makes bash treat\nit as a command to run rather than as a variable and a value with the\ndesire to set one to the other.  Prepending the line with 'declare' or\n'local' or perhaps 'readonly' would fix that, but those aren't posix\nand my reading suggested that while some other shells did support some\nof those builtins, the support was somewhat spotty.  Since\nwrap-for-bin.sh runs under /bin/sh, not /bin/bash, I didn't have a way\nof making the per-process piece work and just fell back to a separate\nvariable.  Maybe we want to change that script to /bin/bash?\n\nDo you see any alternatives I'm missing?\n\nThanks,\nElijah\n"},{"id":"344304","messageId":"nycvar.QRO.7.76.6.1804101023100.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","threadId":"48228","inReplyTo":"CABPp-BF4x-ppjptq1TBj+VicvGeWGbfj4e3f5ne_13AEKmvSQQ@mail.gmail.com","subject":"Re: [PATCH v2] Make running git under other debugger-like programs easy","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-04-10T08:26:37Z","receivedAt":"2018-04-10T08:26:44Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Elijah,\n\nOn Mon, 9 Apr 2018, Elijah Newren wrote:\n\n> On Mon, Apr 9, 2018 at 2:19 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > On Mon, 9 Apr 2018, Elijah Newren wrote:\n> >\n> >>  debug () {\n> >> -      GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n> >> +     case \"$1\" in\n> >> +     -d)\n> >> +             DBG_FLAGS=\"$2\" &&\n> >\n> > Maybe we can find a way that does not require setting a variable other\n> > than GIT_DEBUGGER? After all, DBG_FLAGS will be visible to the script\n> > calling `debug`...\n> \n> I guess we could instead do a\n>    export GIT_DEBUGGER=\"$2\"\n> here.  Short of explicitly using 'export', I think we'd need another\n> environment variable.\n\nI suppose so. The GIT_DEBUGGER variable has to be exported *anyway*,\notherwise the bin-wrappers/* won't see it.\n\n> I would have stuck with your original suggestion, except that by running:\n>     GIT_DEBUGGER=\"$1\" debug_aux \"$@\"\n> GIT_DEBUGGER would be set within the debug_aux function and would NOT\n> be set once bin-wrappers/git was called, making git not run under the\n> debugger as desired.\n\nOh, so in debug_aux, you'd have to do some funny\n\n\tGIT_DEBUGGER=\"$GIT_DEBUGGER\" \"$@\"\n\nto export that variable to the process... Ugly.\n\n> >> +*)\n> >> +     GIT_DEBUGGER_ARGS=\"$GIT_DEBUGGER\"\n> >> +     unset GIT_DEBUGGER\n> >> +     exec ${GIT_DEBUGGER_ARGS} \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n> >\n> > It may not be a big deal, bug GIT_DEBUGGER_ARGS (if it was exported e.g.\n> > by the user calling the script) is now visible by the called process... (I\n> > thought I had tried my best to avoid such a leaking variable in my\n> > patch...)\n> \n> You had a separate, per-process variable:\n> GIT_DEBUGGER_$$=\"$GIT_DEBUGGER\"\n\nRight. And I guess it does not work because the _$$ is not expanded, you'd\nhave to eval it, and then you'd have to quote the right side\nappropriately, and it's all not worth it.\n\n> The problem with that line is that the $$ apparently makes bash treat\n> it as a command to run rather than as a variable and a value with the\n> desire to set one to the other.  Prepending the line with 'declare' or\n> 'local' or perhaps 'readonly' would fix that, but those aren't posix\n> and my reading suggested that while some other shells did support some\n> of those builtins, the support was somewhat spotty.  Since\n> wrap-for-bin.sh runs under /bin/sh, not /bin/bash, I didn't have a way\n> of making the per-process piece work and just fell back to a separate\n> variable.  Maybe we want to change that script to /bin/bash?\n> \n> Do you see any alternatives I'm missing?\n\nNo, not really.\n\nWell, let's stick with your patch (with s/DBG_FLAGS/GIT_DEBUGGER/).\n\nThanks,\nDscho\n"},{"id":"345714","messageId":"20180424234645.8735-1-newren@gmail.com","threadId":"48228","inReplyTo":"nycvar.QRO.7.76.6.1804101023100.55@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz","subject":"[PATCH v3] Make running git under other debugger-like programs easy","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2018-04-24T23:46:45Z","receivedAt":"2018-04-24T23:46:54Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"This allows us to run git, when using the script from bin-wrappers, under\nother programs.  A few examples for usage within testsuite scripts:\n\n   debug git checkout master\n   debug --debugger=nemiver git $ARGS\n   debug -d \"valgrind --tool-memcheck --track-origins=yes\" git $ARGS\n\nOr, if someone has bin-wrappers/ in their $PATH and is executing git\noutside the testsuite:\n\n   GIT_DEBUGGER=\"gdb --args\" git $ARGS\n   GIT_DEBUGGER=nemiver git $ARGS\n   GIT_DEBUGGER=\"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n\nThere is also a handy shortcut of GIT_DEBUGGER=1 meaning the same as\nGIT_DEBUGGER=\"gdb --args\"\n\nOriginal-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\n\nFinally getting back to this now that I have tied up all loose ends\nwith the directory rename detection series (or at least I hope they\nare all tied up).\n\nThere is only one change since v2:\n  s/DBG_FLAGS/GIT_DEBUGGER/, as suggested by Dscho\n\n\n t/test-lib-functions.sh | 24 ++++++++++++++++++++----\n wrap-for-bin.sh         | 19 +++++++++++++------\n 2 files changed, 33 insertions(+), 10 deletions(-)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex b895366fee..a407b09b48 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -145,12 +145,28 @@ test_pause () {\n \t\"$SHELL_PATH\" <&6 >&5 2>&7\n }\n \n-# Wrap git in gdb. Adding this to a command can make it easier to\n-# understand what is going on in a failing test.\n+# Wrap git with a debugger. Adding this to a command can make it easier\n+# to understand what is going on in a failing test.\n #\n-# Example: \"debug git checkout master\".\n+# Examples:\n+#     debug git checkout master\n+#     debug --debugger=nemiver git $ARGS\n+#     debug -d \"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n debug () {\n-\t GIT_TEST_GDB=1 \"$@\" <&6 >&5 2>&7\n+\tcase \"$1\" in\n+\t-d)\n+\t\tGIT_DEBUGGER=\"$2\" &&\n+\t\tshift 2\n+\t\t;;\n+\t--debugger=*)\n+\t\tGIT_DEBUGGER=\"${1#*=}\" &&\n+\t\tshift 1\n+\t\t;;\n+\t*)\n+\t\tGIT_DEBUGGER=1\n+\t\t;;\n+\tesac &&\n+\tGIT_DEBUGGER=\"${GIT_DEBUGGER}\" \"$@\" <&6 >&5 2>&7\n }\n \n # Call test_commit with the arguments\ndiff --git a/wrap-for-bin.sh b/wrap-for-bin.sh\nindex 5842408817..95851b85b6 100644\n--- a/wrap-for-bin.sh\n+++ b/wrap-for-bin.sh\n@@ -20,10 +20,17 @@ PATH='@@BUILD_DIR@@/bin-wrappers:'\"$PATH\"\n \n export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR\n \n-if test -n \"$GIT_TEST_GDB\"\n-then\n-\tunset GIT_TEST_GDB\n-\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n-else\n+case \"$GIT_DEBUGGER\" in\n+'')\n \texec \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n-fi\n+\t;;\n+1)\n+\tunset GIT_DEBUGGER\n+\texec gdb --args \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n+\t;;\n+*)\n+\tGIT_DEBUGGER_ARGS=\"$GIT_DEBUGGER\"\n+\tunset GIT_DEBUGGER\n+\texec ${GIT_DEBUGGER_ARGS} \"${GIT_EXEC_PATH}/@@PROG@@\" \"$@\"\n+\t;;\n+esac\n-- \n2.17.0.2.g31fed8301b\n\n"},{"id":"345739","messageId":"nycvar.QRO.7.76.6.1804250923280.4978@tvgsbejvaqbjf.bet","threadId":"48228","inReplyTo":"20180424234645.8735-1-newren@gmail.com","subject":"Re: [PATCH v3] Make running git under other debugger-like programs easy","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-04-25T07:25:58Z","receivedAt":"2018-04-25T07:26:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Elijah,\n\nOn Tue, 24 Apr 2018, Elijah Newren wrote:\n\n> This allows us to run git, when using the script from bin-wrappers, under\n> other programs.  A few examples for usage within testsuite scripts:\n> \n>    debug git checkout master\n>    debug --debugger=nemiver git $ARGS\n>    debug -d \"valgrind --tool-memcheck --track-origins=yes\" git $ARGS\n> \n> Or, if someone has bin-wrappers/ in their $PATH and is executing git\n> outside the testsuite:\n> \n>    GIT_DEBUGGER=\"gdb --args\" git $ARGS\n>    GIT_DEBUGGER=nemiver git $ARGS\n>    GIT_DEBUGGER=\"valgrind --tool=memcheck --track-origins=yes\" git $ARGS\n> \n> There is also a handy shortcut of GIT_DEBUGGER=1 meaning the same as\n> GIT_DEBUGGER=\"gdb --args\"\n> \n> Original-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> Signed-off-by: Elijah Newren <newren@gmail.com>\n\nLooks good to me!\nDscho\n"},{"id":"345852","messageId":"xmqq604e4tor.fsf@gitster-ct.c.googlers.com","threadId":"48228","inReplyTo":"nycvar.QRO.7.76.6.1804250923280.4978@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v3] Make running git under other debugger-like programs easy","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-26T01:56:04Z","receivedAt":"2018-04-26T01:56:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n>> ...\n>> \n>> There is also a handy shortcut of GIT_DEBUGGER=1 meaning the same as\n>> GIT_DEBUGGER=\"gdb --args\"\n>> \n>> Original-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>> Signed-off-by: Elijah Newren <newren@gmail.com>\n>\n> Looks good to me!\n> Dscho\n\nThanks, both.\n"}]}