Skip to content

Commit c6b80a1

Browse files
committed
Merge branch 'msys2-strace'
Debugging support on MSYS2. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 5c2e29c + 703546a commit c6b80a1

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
@@ -1467,6 +1467,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14671467
const char *(*quote_arg)(const char *arg) =
14681468
is_msys2_sh(cmd ? cmd : *argv) ?
14691469
quote_arg_msys2 : quote_arg_msvc;
1470+
const char *strace_env;
14701471

14711472
do_unset_environment_variables();
14721473

@@ -1525,6 +1526,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
15251526
free(quoted);
15261527
}
15271528

1529+
strace_env = getenv("GIT_STRACE_COMMANDS");
1530+
if (strace_env) {
1531+
char *p = path_lookup("strace.exe", 1);
1532+
if (!p)
1533+
return error("strace not found!");
1534+
if (xutftowcs_path(wcmd, p) < 0) {
1535+
free(p);
1536+
return -1;
1537+
}
1538+
free(p);
1539+
if (!strcmp("1", strace_env) ||
1540+
!strcasecmp("yes", strace_env) ||
1541+
!strcasecmp("true", strace_env))
1542+
strbuf_insert(&args, 0, "strace ", 7);
1543+
else {
1544+
const char *quoted = quote_arg(strace_env);
1545+
struct strbuf buf = STRBUF_INIT;
1546+
strbuf_addf(&buf, "strace -o %s ", quoted);
1547+
if (quoted != strace_env)
1548+
free((char *)quoted);
1549+
strbuf_insert(&args, 0, buf.buf, buf.len);
1550+
strbuf_release(&buf);
1551+
}
1552+
}
1553+
15281554
ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
15291555
xutftowcs(wargs, args.buf, 2 * args.len + 1);
15301556
strbuf_release(&args);

0 commit comments

Comments
 (0)