@matheusbsbs / matheus-bagliano / commits / 3efc128cd5
Fork 0

mingw: help debugging 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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Apr 9, 2020 at 10:21 UTC 3efc128cd59fefb6aa159548d0cf7666ce5e34a9
1 file changed +26
compat/mingw.c
+26
@@ -1488,6 +1488,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1488 const char *(*quote_arg)(const char *arg) =
1489 is_msys2_sh(cmd ? cmd : *argv) ?
1490 quote_arg_msys2 : quote_arg_msvc;
1491 + const char *strace_env;
1492
1493 /* Make sure to override previous errors, if any */
1494 errno = 0;
@@ -1571,6 +1572,31 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1572 free(quoted);
1573 }
1574
1575 + strace_env = getenv("GIT_STRACE_COMMANDS");
1576 + if (strace_env) {
1577 + char *p = path_lookup("strace.exe", 1);
1578 + if (!p)
1579 + return error("strace not found!");
1580 + if (xutftowcs_path(wcmd, p) < 0) {
1581 + free(p);
1582 + return -1;
1583 + }
1584 + free(p);
1585 + if (!strcmp("1", strace_env) ||
1586 + !strcasecmp("yes", strace_env) ||
1587 + !strcasecmp("true", strace_env))
1588 + strbuf_insert(&args, 0, "strace ", 7);
1589 + else {
1590 + const char *quoted = quote_arg(strace_env);
1591 + struct strbuf buf = STRBUF_INIT;
1592 + strbuf_addf(&buf, "strace -o %s ", quoted);
1593 + if (quoted != strace_env)
1594 + free((char *)quoted);
1595 + strbuf_insert(&args, 0, buf.buf, buf.len);
1596 + strbuf_release(&buf);
1597 + }
1598 + }
1599 +
1600 ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
1601 xutftowcs(wargs, args.buf, 2 * args.len + 1);
1602 strbuf_release(&args);