Skip to content

Commit 2dd3603

Browse files
committed
squash! Help debugging with MSys2 by optionally executing bash with strace
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 52a7159 commit 2dd3603

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

compat/mingw.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
15091509
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
15101510
BOOL ret;
15111511
HANDLE cons;
1512+
const char *strace_env;
15121513

15131514
do_unset_environment_variables();
15141515

@@ -1568,7 +1569,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
15681569
free(quoted);
15691570
}
15701571

1571-
if (getenv("GIT_STRACE_COMMANDS")) {
1572+
strace_env = getenv("GIT_STRACE_COMMANDS");
1573+
if (strace_env) {
15721574
char **path = get_path_split();
15731575
char *p = path_lookup("strace.exe", path, 1);
15741576
if (!p) {
@@ -1580,8 +1582,20 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
15801582
free(p);
15811583
return -1;
15821584
}
1583-
strbuf_insert(&args, 0, "strace ", 7);
15841585
free(p);
1586+
if (!strcmp("1", strace_env) ||
1587+
!strcasecmp("yes", strace_env) ||
1588+
!strcasecmp("true", strace_env))
1589+
strbuf_insert(&args, 0, "strace ", 7);
1590+
else {
1591+
const char *quoted = quote_arg(strace_env);
1592+
struct strbuf buf = STRBUF_INIT;
1593+
strbuf_addf(&buf, "strace -o %s ", quoted);
1594+
if (quoted != strace_env)
1595+
free((char *)quoted);
1596+
strbuf_insert(&args, 0, buf.buf, buf.len);
1597+
strbuf_release(&buf);
1598+
}
15851599
}
15861600

15871601
ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));

0 commit comments

Comments
 (0)