summaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2020-04-09 10:21:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-04-10 17:21:07 (GMT)
commit3efc128cd59fefb6aa159548d0cf7666ce5e34a9 (patch)
treed8322852c4b56639b4d3366026d07ee1656be8e8 /compat/mingw.c
parentb6852e19794245566f7c961a434c56ca3b7a883b (diff)
downloadgit-3efc128cd59fefb6aa159548d0cf7666ce5e34a9.zip
git-3efc128cd59fefb6aa159548d0cf7666ce5e34a9.tar.gz
git-3efc128cd59fefb6aa159548d0cf7666ce5e34a9.tar.bz2
mingw: help debugging by optionally executing bash with strace
MSYS2's strace facility is very useful for debugging... With this patch, the bash will be executed through strace if the environment variable GIT_STRACE_COMMANDS is set, which comes in real handy when investigating issues in the test suite. Also support passing a path to a log file via GIT_STRACE_COMMANDS to force Git to call strace.exe with the `-o <path>` argument, i.e. to log into a file rather than print the log directly. That comes in handy when the output would otherwise misinterpreted by a calling process as part of Git's output. Note: the values "1", "yes" or "true" are *not* specifying paths, but tell Git to let strace.exe log directly to the console. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index f2c94f9..178a70d 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1488,6 +1488,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
const char *(*quote_arg)(const char *arg) =
is_msys2_sh(cmd ? cmd : *argv) ?
quote_arg_msys2 : quote_arg_msvc;
+ const char *strace_env;
/* Make sure to override previous errors, if any */
errno = 0;
@@ -1571,6 +1572,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
free(quoted);
}
+ strace_env = getenv("GIT_STRACE_COMMANDS");
+ if (strace_env) {
+ char *p = path_lookup("strace.exe", 1);
+ if (!p)
+ return error("strace not found!");
+ if (xutftowcs_path(wcmd, p) < 0) {
+ free(p);
+ return -1;
+ }
+ free(p);
+ if (!strcmp("1", strace_env) ||
+ !strcasecmp("yes", strace_env) ||
+ !strcasecmp("true", strace_env))
+ strbuf_insert(&args, 0, "strace ", 7);
+ else {
+ const char *quoted = quote_arg(strace_env);
+ struct strbuf buf = STRBUF_INIT;
+ strbuf_addf(&buf, "strace -o %s ", quoted);
+ if (quoted != strace_env)
+ free((char *)quoted);
+ strbuf_insert(&args, 0, buf.buf, buf.len);
+ strbuf_release(&buf);
+ }
+ }
+
ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
xutftowcs(wargs, args.buf, 2 * args.len + 1);
strbuf_release(&args);