{"thread":{"id":"53197","subject":"[PATCH] mingw: help debugging by optionally executing bash with strace","startedAt":"2020-04-09T10:21:53Z","lastAt":"2020-04-09T10:21:53Z","messageCount":1,"participants":["Johannes Schindelin via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"395111","messageId":"pull.604.git.1586427707655.gitgitgadget@gmail.com","threadId":"53197","inReplyTo":null,"subject":"[PATCH] mingw: help debugging by optionally executing bash with strace","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-04-09T10:21:47Z","receivedAt":"2020-04-09T10:21:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nMSYS2's strace facility is very useful for debugging... With this patch,\nthe bash will be executed through strace if the environment variable\nGIT_STRACE_COMMANDS is set, which comes in real handy when investigating\nissues in the test suite.\n\nAlso support passing a path to a log file via GIT_STRACE_COMMANDS to\nforce Git to call strace.exe with the `-o <path>` argument, i.e. to log\ninto a file rather than print the log directly.\n\nThat comes in handy when the output would otherwise misinterpreted by a\ncalling process as part of Git's output.\n\nNote: the values \"1\", \"yes\" or \"true\" are *not* specifying paths, but\ntell Git to let strace.exe log directly to the console.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    mingw: help debugging by optionally executing bash with MSYS2's strace\n    \n    This is another patch that has been carried in Git for Windows for some\n    five years. Time to graduate.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-604%2Fdscho%2Fmsys2-strace-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-604/dscho/msys2-strace-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/604\n\n compat/mingw.c | 26 ++++++++++++++++++++++++++\n 1 file changed, 26 insertions(+)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex d14065d60ec..60c0d36764b 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1479,6 +1479,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen\n \tconst char *(*quote_arg)(const char *arg) =\n \t\tis_msys2_sh(cmd ? cmd : *argv) ?\n \t\tquote_arg_msys2 : quote_arg_msvc;\n+\tconst char *strace_env;\n \n \t/* Make sure to override previous errors, if any */\n \terrno = 0;\n@@ -1562,6 +1563,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen\n \t\t\tfree(quoted);\n \t}\n \n+\tstrace_env = getenv(\"GIT_STRACE_COMMANDS\");\n+\tif (strace_env) {\n+\t\tchar *p = path_lookup(\"strace.exe\", 1);\n+\t\tif (!p)\n+\t\t\treturn error(\"strace not found!\");\n+\t\tif (xutftowcs_path(wcmd, p) < 0) {\n+\t\t\tfree(p);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tfree(p);\n+\t\tif (!strcmp(\"1\", strace_env) ||\n+\t\t    !strcasecmp(\"yes\", strace_env) ||\n+\t\t    !strcasecmp(\"true\", strace_env))\n+\t\t\tstrbuf_insert(&args, 0, \"strace \", 7);\n+\t\telse {\n+\t\t\tconst char *quoted = quote_arg(strace_env);\n+\t\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\t\tstrbuf_addf(&buf, \"strace -o %s \", quoted);\n+\t\t\tif (quoted != strace_env)\n+\t\t\t\tfree((char *)quoted);\n+\t\t\tstrbuf_insert(&args, 0, buf.buf, buf.len);\n+\t\t\tstrbuf_release(&buf);\n+\t\t}\n+\t}\n+\n \tALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));\n \txutftowcs(wargs, args.buf, 2 * args.len + 1);\n \tstrbuf_release(&args);\n\nbase-commit: 9fadedd637b312089337d73c3ed8447e9f0aa775\n-- \ngitgitgadget\n"}]}