]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mingw: add a helper function to attach GDB to the current process
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 13 Feb 2020 21:49:53 +0000 (21:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Feb 2020 18:02:07 +0000 (10:02 -0800)
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c
compat/mingw.h

index bd24d913f93f3cc077eb0d7545dfebf2491a4aac..6b36d0387aa3a542291d5eef8f6c5e5bddb298d7 100644 (file)
 
 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;
index 04ca731a6b76887390fae4f2fa7b5f7c8c56905a..88c07c452097843bfd0d9372f94adc7c77da3bf6 100644 (file)
@@ -591,6 +591,16 @@ extern CRITICAL_SECTION pinfo_cs;
 int wmain(int argc, const wchar_t **w_argv);
 int main(int argc, const char **argv);
 
+/*
+ * For debugging: if a problem occurs, say, in a Git process that is spawned
+ * from another Git process which in turn is spawned from yet another Git
+ * process, it can be quite daunting to figure out what is going on.
+ *
+ * Call this function to open a new MinTTY (this assumes you are in Git for
+ * Windows' SDK) with a GDB that attaches to the current process right away.
+ */
+extern void open_in_gdb(void);
+
 /*
  * Used by Pthread API implementation for Windows
  */