Skip to content

Commit 4e70acd

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge branch 'msys2-strace'
Debugging support on MSYS2. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 25c5822 + 5699c3b commit 4e70acd

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
@@ -1487,6 +1487,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14871487
const char *(*quote_arg)(const char *arg) =
14881488
is_msys2_sh(cmd ? cmd : *argv) ?
14891489
quote_arg_msys2 : quote_arg_msvc;
1490+
const char *strace_env;
14901491

14911492
/* Make sure to override previous errors, if any */
14921493
errno = 0;
@@ -1570,6 +1571,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
15701571
free(quoted);
15711572
}
15721573

1574+
strace_env = getenv("GIT_STRACE_COMMANDS");
1575+
if (strace_env) {
1576+
char *p = path_lookup("strace.exe", 1);
1577+
if (!p)
1578+
return error("strace not found!");
1579+
if (xutftowcs_path(wcmd, p) < 0) {
1580+
free(p);
1581+
return -1;
1582+
}
1583+
free(p);
1584+
if (!strcmp("1", strace_env) ||
1585+
!strcasecmp("yes", strace_env) ||
1586+
!strcasecmp("true", strace_env))
1587+
strbuf_insert(&args, 0, "strace ", 7);
1588+
else {
1589+
const char *quoted = quote_arg(strace_env);
1590+
struct strbuf buf = STRBUF_INIT;
1591+
strbuf_addf(&buf, "strace -o %s ", quoted);
1592+
if (quoted != strace_env)
1593+
free((char *)quoted);
1594+
strbuf_insert(&args, 0, buf.buf, buf.len);
1595+
strbuf_release(&buf);
1596+
}
1597+
}
1598+
15731599
ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
15741600
xutftowcs(wargs, args.buf, 2 * args.len + 1);
15751601
strbuf_release(&args);

0 commit comments

Comments
 (0)