path: root/compat/mingw.c
diff options
authorJohannes Schindelin <>2020-02-13 21:49:53 (GMT)
committerJunio C Hamano <>2020-02-14 18:02:07 (GMT)
commit08809c09aa1351b603e9c55734105cd2e3c24c41 (patch)
tree8484465b2e13ac0d8a71dce4a128b7d824d84971 /compat/mingw.c
parentb6d4d82bd5a49197d5d2f4f81c08da0d461cfcf1 (diff)
mingw: add a helper function to attach GDB to the current process
When debugging Git, the criss-cross spawning of processes can make things quite a bit difficult, especially when a Unix shell script is thrown in the mix that calls a `git.exe` that then segfaults. To help debugging such things, we introduce the `open_in_gdb()` function which can be called at a code location where the segfault happens (or as close as one can get); This will open a new MinTTY window with a GDB that already attached to the current process. Inspired by Derrick Stolee. Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'compat/mingw.c')
1 files changed, 13 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index bd24d91..6b36d03 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -13,6 +13,19 @@
static const int delay[] = { 0, 1, 10, 20, 40 };
+void open_in_gdb(void)
+ static struct child_process cp = CHILD_PROCESS_INIT;
+ extern char *_pgmptr;
+ argv_array_pushl(&cp.args, "mintty", "gdb", NULL);
+ argv_array_pushf(&cp.args, "--pid=%d", getpid());
+ cp.clean_on_exit = 1;
+ if (start_command(&cp) < 0)
+ die_errno("Could not start gdb");
+ sleep(1);
int err_win_to_posix(DWORD winerr)
int error = ENOSYS;