diff --git a/src/Ryujinx.HLE/Debugger/Debugger.cs b/src/Ryujinx.HLE/Debugger/Debugger.cs index a5a60cf7c..7c9815d60 100644 --- a/src/Ryujinx.HLE/Debugger/Debugger.cs +++ b/src/Ryujinx.HLE/Debugger/Debugger.cs @@ -1,4 +1,4 @@ -using Ryujinx.Common; +using Ryujinx.Common; using Ryujinx.Common.Logging; using Ryujinx.Memory; using System; @@ -8,6 +8,7 @@ using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; +using IExecutionContext = Ryujinx.Cpu.IExecutionContext; namespace Ryujinx.HLE.Debugger { @@ -134,6 +135,11 @@ namespace Ryujinx.HLE.Debugger WriteStream.WriteByte((byte)'+'); ProcessCommand(cmd); break; + + case ThreadBreakMessage msg: + HaltApplication(); + Reply($"T05thread:{msg.Context.ThreadUid:x};"); + break; } } } @@ -641,5 +647,14 @@ namespace Ryujinx.HLE.Debugger HandlerThread.Join(); } } + + public void ThreadBreak(IExecutionContext ctx, ulong address, int imm) + { + ctx.DebugStop(); + + Logger.Notice.Print(LogClass.GdbStub, $"Break hit on thread {ctx.ThreadUid} at pc {address:x016}"); + + Messages.Add(new ThreadBreakMessage(ctx, address, imm)); + } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/Debugger/Message/ThreadBreakMessage.cs b/src/Ryujinx.HLE/Debugger/Message/ThreadBreakMessage.cs new file mode 100644 index 000000000..ac0ecdefb --- /dev/null +++ b/src/Ryujinx.HLE/Debugger/Message/ThreadBreakMessage.cs @@ -0,0 +1,18 @@ +using IExecutionContext = Ryujinx.Cpu.IExecutionContext; + +namespace Ryujinx.HLE.Debugger +{ + public class ThreadBreakMessage : IMessage + { + public IExecutionContext Context { get; } + public ulong Address { get; } + public int Opcode { get; } + + public ThreadBreakMessage(IExecutionContext context, ulong address, int opcode) + { + Context = context; + Address = address; + Opcode = opcode; + } + } +} diff --git a/src/Ryujinx.HLE/FileSystem/ContentManager.cs b/src/Ryujinx.HLE/FileSystem/ContentManager.cs index e6c0fce08..ff9bef55b 100644 --- a/src/Ryujinx.HLE/FileSystem/ContentManager.cs +++ b/src/Ryujinx.HLE/FileSystem/ContentManager.cs @@ -964,4 +964,4 @@ namespace Ryujinx.HLE.FileSystem return null; } } -} +} \ No newline at end of file diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs index c18fadf8d..31a8ab916 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs @@ -730,9 +730,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public IExecutionContext CreateExecutionContext() { + ExceptionCallback breakCallback = null; + + if (KernelContext.Device.Configuration.EnableGdbStub) + { + breakCallback = KernelContext.Device.Debugger.ThreadBreak; + } + return Context?.CreateExecutionContext(new ExceptionCallbacks( InterruptHandler, - null, + breakCallback, KernelContext.SyscallHandler.SvcCall, UndefinedInstructionHandler)); }