From 84e078f94c89131a30116d9920d0c62e6be7d13b Mon Sep 17 00:00:00 2001 From: Coxxs <58-coxxs@users.noreply.git.ryujinx.app> Date: Sat, 21 Jun 2025 01:05:25 +0800 Subject: [PATCH] gdb: Wait for the application to start if user connect gdb too early --- src/Ryujinx.HLE/Debugger/Debugger.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.HLE/Debugger/Debugger.cs b/src/Ryujinx.HLE/Debugger/Debugger.cs index 3eebb0b38..3ec4dbb93 100644 --- a/src/Ryujinx.HLE/Debugger/Debugger.cs +++ b/src/Ryujinx.HLE/Debugger/Debugger.cs @@ -47,7 +47,7 @@ namespace Ryujinx.HLE.Debugger MessageHandlerThread.Start(); } - private IDebuggableProcess DebugProcess => Device.System.DebugGetApplicationProcess(); + private IDebuggableProcess DebugProcess => Device.System?.DebugGetApplicationProcess(); private KThread[] GetThreads() => DebugProcess.GetThreadUids().Select(x => DebugProcess.GetThread(x)).ToArray(); private bool IsProcessAarch32 => DebugProcess.GetThread(gThread.Value).Context.IsAarch32; private KernelContext KernelContext => Device.System.KernelContext; @@ -761,6 +761,20 @@ namespace Ryujinx.HLE.Debugger { return; } + + // If the user connects before the application is running, wait for the application to start. + int retries = 10; + while (DebugProcess == null && retries-- > 0) + { + Thread.Sleep(200); + } + if (DebugProcess == null) + { + Logger.Warning?.Print(LogClass.GdbStub, "Application is not running, cannot accept GDB client connection"); + ClientSocket.Close(); + continue; + } + ClientSocket.NoDelay = true; ReadStream = new NetworkStream(ClientSocket, System.IO.FileAccess.Read); WriteStream = new NetworkStream(ClientSocket, System.IO.FileAccess.Write);