From 351730d585a85f97c26bcabe93b2fddea19107ec Mon Sep 17 00:00:00 2001
From: Ian Chamberlain <ian.h.chamberlain@gmail.com>
Date: Fri, 31 Mar 2023 14:06:43 -0400
Subject: [PATCH] Fix infinite hang if GDB client kills gdbstub

---
 src/core/gdbstub/gdbstub.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 09f29be46..281ba3d62 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -1066,12 +1066,15 @@ void HandlePacket() {
         SendSignal(current_thread, latest_signal);
         break;
     case 'k':
-        Shutdown();
+        ToggleServer(false);
+        // Continue execution so we don't hang forever after shutting down the
+        // server
+        Continue();
         LOG_INFO(Debug_GDBStub, "killed by gdb");
         return;
     case 'F':
         if (HandleHioReply(command_buffer, command_length)) {
-            // TODO: technically if we were paused when the reply came in, we
+            // TODO: technically if we were paused when the request came in, we
             // shouldn't continue here. Could recurse back into HandlePacket() maybe??
             Continue();
         } else {