)]}'
{
  "commit": "56f4dea207d690fff70a3ccb6fe10ebe1e4697c0",
  "tree": "4c4854b15c26ab4222ba06b94e8fd5a2310385e5",
  "parents": [
    "5739a1b98daf68fd81fed9af9667a2b9671928f9"
  ],
  "author": {
    "name": "Pedro Alves",
    "email": "pedro@palves.net",
    "time": "Wed Apr 17 18:57:01 2024 +0100"
  },
  "committer": {
    "name": "Pedro Alves",
    "email": "pedro@palves.net",
    "time": "Wed Apr 17 18:57:01 2024 +0100"
  },
  "message": "gdb/Windows: Fix detach while running\n\nWhile testing a WIP Cygwin GDB that supports non-stop, I noticed that\ngdb.threads/attach-non-stop.exp exposes that this:\n\n (gdb) attach PID\u0026\n ...\n (gdb) detach\n\n... hangs.\n\nAnd it turns out that it hangs in all-stop as well.  This commits\nfixes that.\n\nAfter \"attach \u0026\", the target is set running, we\u0027ve called\nContinueDebugEvent and the process_thread thread is waiting for\nWaitForDebugEvent events.  It is the equivalent of \"attach; c\u0026\".\n\nIn windows_nat_target::detach, the first thing we do is\nunconditionally call windows_continue (for ContinueDebugEvent), which\nblocks in do_synchronously, until the process_thread sees an event out\nof WaitForDebugEvent.  Unless the inferior happens to run into a\nbreakpoint, etc., then this hangs indefinitely.\n\nIf we\u0027ve already called ContinueDebugEvent earlier, then we shouldn\u0027t\nbe calling it again in ::detach.\n\nStill in windows_nat_target::detach, we have an interesting issue that\nends up being the bulk of the patch -- only the process_thread thread\ncan call DebugActiveProcessStop, but if it is blocked in\nWaitForDebugEvent, we need to somehow force it to break out of it.\nThe only way to do that, is to force the inferior to do something that\ncauses WaitForDebugEvent to return some event.\n\nThis patch uses CreateRemoteThread to do it, which results in\nWaitForDebugEvent reporting CREATE_THREAD_DEBUG_EVENT.  We then\nterminate the injected thread before it has a chance to run any\nuserspace code.\n\nNote that Win32 functions like DebugBreakProcess and\nGenerateConsoleCtrlEvent would also inject a new thread in the\ninferior.  I first used DebugBreakProcess, but that is actually more\ncomplicated to use, because we\u0027d have to be sure to consume the\nbreakpoint event before detaching, otherwise the inferior would likely\ndie due a breakpoint exception being raised with no debugger around to\nintercept it.\n\nSee the new break_out_process_thread method.\n\nSo the fix has two parts:\n\n - Keep track of whether we\u0027ve called ContinueDebugEvent and the\n   process_thread thread is waiting for events, or whether\n   WaitForDebugEvent already returned an event.\n\n - In windows_nat_target::detach, if the process_thread thread is\n   waiting for events, unblock out of its WaitForDebugEvent, before\n   proceeding with the actual detach.\n\nNew test included.  Passes cleanly on GNU/Linux native and gdbserver,\nand also passes cleanly on Cygwin and MinGW, with the fix.  Before the\nfix, it would hang and fail with a timeout.\n\nTested-By: Hannes Domani \u003cssbssa@yahoo.de\u003e\nReviewed-By: Tom Tromey \u003ctom@tromey.com\u003e\nChange-Id: Ifb91c58c08af1a9bcbafecedc93dfce001040905\n",
  "tree_diff": [
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9c038f4af1893e2caa30201b09393cb9743450d5",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.base/detach-while-running.c"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "4ce6c7045ea5d27f7ec348805cc29941516887ad",
      "new_mode": 33188,
      "new_path": "gdb/testsuite/gdb.base/detach-while-running.exp"
    },
    {
      "type": "modify",
      "old_id": "6fc412310236d725fb60e244794e0fa0e4e25cdd",
      "old_mode": 33188,
      "old_path": "gdb/windows-nat.c",
      "new_id": "a53b6a6e053edc768a1d1658ed28aebc92c4c789",
      "new_mode": 33188,
      "new_path": "gdb/windows-nat.c"
    }
  ]
}
