Skip to content

Commit 5699c3b

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 6e2bcc8 commit 5699c3b

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
@@ -1479,6 +1479,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14791479
const char *(*quote_arg)(const char *arg) =
14801480
is_msys2_sh(cmd ? cmd : *argv) ?
14811481
quote_arg_msys2 : quote_arg_msvc;
1482+
const char *strace_env;
14821483

14831484
/* Make sure to override previous errors, if any */
14841485
errno = 0;
@@ -1562,6 +1563,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
15621563
free(quoted);
15631564
}
15641565

1566+
strace_env = getenv("GIT_STRACE_COMMANDS");
1567+
if (strace_env) {
1568+
char *p = path_lookup("strace.exe", 1);
1569+
if (!p)
1570+
return error("strace not found!");
1571+
if (xutftowcs_path(wcmd, p) < 0) {
1572+
free(p);
1573+
return -1;
1574+
}
1575+
free(p);
1576+
if (!strcmp("1", strace_env) ||
1577+
!strcasecmp("yes", strace_env) ||
1578+
!strcasecmp("true", strace_env))
1579+
strbuf_insert(&args, 0, "strace ", 7);
1580+
else {
1581+
const char *quoted = quote_arg(strace_env);
1582+
struct strbuf buf = STRBUF_INIT;
1583+
strbuf_addf(&buf, "strace -o %s ", quoted);
1584+
if (quoted != strace_env)
1585+
free((char *)quoted);
1586+
strbuf_insert(&args, 0, buf.buf, buf.len);
1587+
strbuf_release(&buf);
1588+
}
1589+
}
1590+
15651591
ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
15661592
xutftowcs(wargs, args.buf, 2 * args.len + 1);
15671593
strbuf_release(&args);

0 commit comments

Comments
 (0)