From 0396997c17e2be07ba8c62a3985ec77f1acc2c64 Mon Sep 17 00:00:00 2001 From: svc64 Date: Tue, 12 Dec 2023 20:29:33 +0200 Subject: [PATCH] Bring back the debugger message handler thread --- src/Ryujinx.HLE/Debugger/Debugger.cs | 51 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Ryujinx.HLE/Debugger/Debugger.cs b/src/Ryujinx.HLE/Debugger/Debugger.cs index 7b87f0eb7e..4b4af540a2 100644 --- a/src/Ryujinx.HLE/Debugger/Debugger.cs +++ b/src/Ryujinx.HLE/Debugger/Debugger.cs @@ -28,6 +28,7 @@ namespace Ryujinx.HLE.Debugger private NetworkStream WriteStream = null; private BlockingCollection Messages = new BlockingCollection(1); private Thread DebuggerThread; + private Thread MessageHandlerThread; private bool _shuttingDown = false; private ulong? cThread; @@ -42,6 +43,8 @@ namespace Ryujinx.HLE.Debugger DebuggerThread = new Thread(DebuggerThreadMain); DebuggerThread.Start(); + MessageHandlerThread = new Thread(MessageHandlerMain); + MessageHandlerThread.Start(); } private IDebuggableProcess DebugProcess => Device.System.DebugGetApplicationProcess(); @@ -138,29 +141,33 @@ namespace Ryujinx.HLE.Debugger } } - private void HandleMessage(IMessage msg) + private void MessageHandlerMain() { - switch (msg) + while (!_shuttingDown) { - case BreakInMessage: - Logger.Notice.Print(LogClass.GdbStub, "Break-in requested"); - CommandQuery(); - break; + IMessage msg = Messages.Take(); + switch (msg) + { + case BreakInMessage: + Logger.Notice.Print(LogClass.GdbStub, "Break-in requested"); + CommandQuery(); + break; - case SendNackMessage: - WriteStream.WriteByte((byte)'-'); - break; + case SendNackMessage: + WriteStream.WriteByte((byte)'-'); + break; - case CommandMessage { Command: var cmd }: - Logger.Debug?.Print(LogClass.GdbStub, $"Received Command: {cmd}"); - WriteStream.WriteByte((byte)'+'); - ProcessCommand(cmd); - break; + case CommandMessage { Command: var cmd }: + Logger.Debug?.Print(LogClass.GdbStub, $"Received Command: {cmd}"); + WriteStream.WriteByte((byte)'+'); + ProcessCommand(cmd); + break; - case ThreadBreakMessage { Context: var ctx }: - DebugProcess.DebugStop(); - Reply($"T05thread:{ctx.ThreadUid:x};"); - break; + case ThreadBreakMessage { Context: var ctx }: + DebugProcess.DebugStop(); + Reply($"T05thread:{ctx.ThreadUid:x};"); + break; + } } } @@ -621,7 +628,7 @@ namespace Ryujinx.HLE.Debugger Logger.Notice.Print(LogClass.GdbStub, "NACK received!"); continue; case '\x03': - HandleMessage(new BreakInMessage()); + Messages.Add(new BreakInMessage()); break; case '$': string cmd = ""; @@ -638,11 +645,11 @@ namespace Ryujinx.HLE.Debugger string checksum = $"{(char)ReadStream.ReadByte()}{(char)ReadStream.ReadByte()}"; if (checksum == $"{CalculateChecksum(cmd):x2}") { - HandleMessage(new CommandMessage(cmd)); + Messages.Add(new CommandMessage(cmd)); } else { - HandleMessage(new SendNackMessage()); + Messages.Add(new SendNackMessage()); } break; @@ -725,6 +732,8 @@ namespace Ryujinx.HLE.Debugger ReadStream?.Close(); WriteStream?.Close(); DebuggerThread.Join(); + Messages.Dispose(); + MessageHandlerThread.Join(); } }