gdb: Prevent BreakHandler being called multiple times from the same breakpoint

This commit is contained in:
Coxxs 2025-06-24 07:25:47 +08:00
parent 669179ca2e
commit cd2a7c9916

View file

@ -32,6 +32,7 @@ namespace Ryujinx.HLE.Debugger
private Thread DebuggerThread;
private Thread MessageHandlerThread;
private bool _shuttingDown = false;
private ManualResetEventSlim _breakHandlerEvent = new ManualResetEventSlim(false);
private ulong? cThread;
private ulong? gThread;
@ -237,6 +238,7 @@ namespace Ryujinx.HLE.Debugger
case ThreadBreakMessage { Context: var ctx }:
DebugProcess.DebugStop();
gThread = cThread = ctx.ThreadUid;
_breakHandlerEvent.Set();
Reply($"T05thread:{ctx.ThreadUid:x};");
break;
@ -1266,15 +1268,20 @@ namespace Ryujinx.HLE.Debugger
Messages.Add(new KillMessage());
MessageHandlerThread.Join();
Messages.Dispose();
_breakHandlerEvent.Dispose();
}
}
public void BreakHandler(IExecutionContext ctx, ulong address, int imm)
{
Logger.Notice.Print(LogClass.GdbStub, $"Break hit on thread {ctx.ThreadUid} at pc {address:x016}");
Messages.Add(new ThreadBreakMessage(ctx, address, imm));
DebugProcess.DebugInterruptHandler(ctx);
_breakHandlerEvent.Reset();
Messages.Add(new ThreadBreakMessage(ctx, address, imm));
// Messages.Add can block, so we log it after adding the message to make sure user can see the log at the same time GDB receives the break message
Logger.Notice.Print(LogClass.GdbStub, $"Break hit on thread {ctx.ThreadUid} at pc {address:x016}");
// Wait for the process to stop before returning to avoid BreakHander being called multiple times from the same breakpoint
_breakHandlerEvent.Wait(5000);
}
public void StepHandler(IExecutionContext ctx)