From 09a63ba2b50e2d76ef83d7de72575dec2f3e04b0 Mon Sep 17 00:00:00 2001 From: merry Date: Sun, 13 Feb 2022 16:43:55 +0000 Subject: [PATCH] Notify debugger on BRK instruction # Conflicts: # src/Ryujinx.HLE/Debugger/Debugger.cs # src/Ryujinx.HLE/Debugger/Message/ThreadBreakMessage.cs # src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs --- src/Ryujinx.HLE/Debugger/Debugger.cs | 19 +++++++++++++++++-- .../Debugger/Message/ThreadBreakMessage.cs | 18 ++++++++++++++++++ src/Ryujinx.HLE/FileSystem/ContentManager.cs | 2 +- .../HOS/Kernel/Process/KProcess.cs | 9 ++++++++- 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/Ryujinx.HLE/Debugger/Message/ThreadBreakMessage.cs 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)); }