gdb: Fix the crash that occurs when GDB is connected early

* "Suspend Application on Start" is on
This commit is contained in:
Coxxs
2025-10-11 21:22:40 -05:00
committed by KeatonTheBot
parent 83412689b7
commit b28f52387a
+10 -4
View File
@@ -859,7 +859,13 @@ namespace Ryujinx.HLE.Debugger
{ {
if (threadId is 0 or null) if (threadId is 0 or null)
{ {
threadId = GetThreads().First().ThreadUid; var threads = GetThreads();
if (threads.Length == 0)
{
ReplyError();
return;
}
threadId = threads.First().ThreadUid;
} }
if (DebugProcess.GetThread(threadId.Value) == null) if (DebugProcess.GetThread(threadId.Value) == null)
@@ -1037,7 +1043,7 @@ namespace Ryujinx.HLE.Debugger
string response = command.Trim().ToLowerInvariant() switch string response = command.Trim().ToLowerInvariant() switch
{ {
"help" => "backtrace\nbt\nregisters\nreg\nget info\nminidump", "help" => "backtrace\nbt\nregisters\nreg\nget info\nminidump\n",
"get info" => GetProcessInfo(), "get info" => GetProcessInfo(),
"backtrace" => GetStackTrace(), "backtrace" => GetStackTrace(),
"bt" => GetStackTrace(), "bt" => GetStackTrace(),
@@ -1192,11 +1198,11 @@ namespace Ryujinx.HLE.Debugger
// If the user connects before the application is running, wait for the application to start. // If the user connects before the application is running, wait for the application to start.
int retries = 10; int retries = 10;
while (DebugProcess == null && retries-- > 0) while ((DebugProcess == null || GetThreads().Length == 0) && retries-- > 0)
{ {
Thread.Sleep(200); Thread.Sleep(200);
} }
if (DebugProcess == null) if (DebugProcess == null || GetThreads().Length == 0)
{ {
Logger.Warning?.Print(LogClass.GdbStub, "Application is not running, cannot accept GDB client connection"); Logger.Warning?.Print(LogClass.GdbStub, "Application is not running, cannot accept GDB client connection");
ClientSocket.Close(); ClientSocket.Close();