Skip to content

Commit debfe3e

Browse files
committed
Merge pull request git-for-windows#1915 from dscho/open-in-gdb
Add a helper function to start GDB that was already attached to the current process
2 parents 11b142d + 3b7fb66 commit debfe3e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

compat/mingw.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313

1414
static const int delay[] = { 0, 1, 10, 20, 40 };
1515

16+
void open_in_gdb(void)
17+
{
18+
static struct child_process cp = CHILD_PROCESS_INIT;
19+
extern char *_pgmptr;
20+
21+
argv_array_pushl(&cp.args, "mintty", "gdb", NULL);
22+
argv_array_pushf(&cp.args, "--pid=%d", getpid());
23+
cp.clean_on_exit = 1;
24+
if (start_command(&cp) < 0)
25+
die_errno("Could not start gdb");
26+
sleep(1);
27+
}
28+
1629
int err_win_to_posix(DWORD winerr)
1730
{
1831
int error = ENOSYS;

compat/mingw.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,16 @@ int main(int argc, const char **argv) \
576576
} \
577577
static int mingw_main(c,v)
578578

579+
/*
580+
* For debugging: if a problem occurs, say, in a Git process that is spawned
581+
* from another Git process which in turn is spawned from yet another Git
582+
* process, it can be quite daunting to figure out what is going on.
583+
*
584+
* Call this function to open a new MinTTY (this assumes you are in Git for
585+
* Windows' SDK) with a GDB that attaches to the current process right away.
586+
*/
587+
extern void open_in_gdb(void);
588+
579589
/*
580590
* Used by Pthread API implementation for Windows
581591
*/

0 commit comments

Comments
 (0)