Skip to content

Commit c63d093

Browse files
committed
Merge branch 'msys2-strace'
Debugging support on MSYS2. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 3c43f54 + 4ed2ca6 commit c63d093

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
@@ -1428,6 +1428,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14281428
HANDLE cons;
14291429
const char *(*quote_arg)(const char *arg) =
14301430
is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
1431+
const char *strace_env;
14311432

14321433
do_unset_environment_variables();
14331434

@@ -1486,6 +1487,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14861487
free(quoted);
14871488
}
14881489

1490+
strace_env = getenv("GIT_STRACE_COMMANDS");
1491+
if (strace_env) {
1492+
char *p = path_lookup("strace.exe", 1);
1493+
if (!p)
1494+
return error("strace not found!");
1495+
if (xutftowcs_path(wcmd, p) < 0) {
1496+
free(p);
1497+
return -1;
1498+
}
1499+
free(p);
1500+
if (!strcmp("1", strace_env) ||
1501+
!strcasecmp("yes", strace_env) ||
1502+
!strcasecmp("true", strace_env))
1503+
strbuf_insert(&args, 0, "strace ", 7);
1504+
else {
1505+
const char *quoted = quote_arg(strace_env);
1506+
struct strbuf buf = STRBUF_INIT;
1507+
strbuf_addf(&buf, "strace -o %s ", quoted);
1508+
if (quoted != strace_env)
1509+
free((char *)quoted);
1510+
strbuf_insert(&args, 0, buf.buf, buf.len);
1511+
strbuf_release(&buf);
1512+
}
1513+
}
1514+
14891515
ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
14901516
xutftowcs(wargs, args.buf, 2 * args.len + 1);
14911517
strbuf_release(&args);

0 commit comments

Comments
 (0)