Skip to content

Commit a254198

Browse files
committed
Help debugging with MSys2 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 <[email protected]>
1 parent 068bb77 commit a254198

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

compat/mingw.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14371437
HANDLE cons;
14381438
const char *(*quote_arg)(const char *arg) =
14391439
is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
1440+
const char *strace_env;
14401441

14411442
do_unset_environment_variables();
14421443

@@ -1494,6 +1495,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14941495
free(quoted);
14951496
}
14961497

1498+
strace_env = getenv("GIT_STRACE_COMMANDS");
1499+
if (strace_env) {
1500+
char *p = path_lookup("strace.exe", 1);
1501+
if (!p)
1502+
return error("strace not found!");
1503+
if (xutftowcs_path(wcmd, p) < 0) {
1504+
free(p);
1505+
return -1;
1506+
}
1507+
free(p);
1508+
if (!strcmp("1", strace_env) ||
1509+
!strcasecmp("yes", strace_env) ||
1510+
!strcasecmp("true", strace_env))
1511+
strbuf_insert(&args, 0, "strace ", 7);
1512+
else {
1513+
const char *quoted = quote_arg(strace_env);
1514+
struct strbuf buf = STRBUF_INIT;
1515+
strbuf_addf(&buf, "strace -o %s ", quoted);
1516+
if (quoted != strace_env)
1517+
free((char *)quoted);
1518+
strbuf_insert(&args, 0, buf.buf, buf.len);
1519+
strbuf_release(&buf);
1520+
}
1521+
}
1522+
14971523
ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
14981524
xutftowcs(wargs, args.buf, 2 * args.len + 1);
14991525
strbuf_release(&args);

0 commit comments

Comments
 (0)