From 9f30c1c5cfd6bc212eee28aa2fc8130abc93a712 Mon Sep 17 00:00:00 2001 From: Hecate2 <2474101468@qq.com> Date: Wed, 14 Aug 2024 11:07:24 +0800 Subject: [PATCH] improve StepOverSourceCode --- Fairy.Debugger.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Fairy.Debugger.cs b/Fairy.Debugger.cs index 6eea433..ee1b6db 100644 --- a/Fairy.Debugger.cs +++ b/Fairy.Debugger.cs @@ -313,16 +313,32 @@ private FairyEngine StepOverSourceCode(FairyEngine engine, out BreakReason break if (engine.State == VMState.BREAK) engine.State = VMState.NONE; UInt160 prevScriptHash = engine.CurrentScriptHash; - int invocationStackCount = engine.InvocationStack.Count; + uint prevInstructionPointer = (uint)engine.CurrentContext!.InstructionPointer; + SourceFilenameAndLineNum prevSourceCode = contractScriptHashToAllInstructionPointerToSourceLineNum[prevScriptHash][prevInstructionPointer]; + int prevInvocationStackCount = engine.InvocationStack.Count; while (engine.State == VMState.NONE) { engine = ExecuteAndCheck(engine, out breakReason, requiredBreakReason: BreakReason.AssemblyBreakpoint | BreakReason.SourceCodeBreakpoint | BreakReason.SourceCode); if (engine.State == VMState.BREAK) { - if ((breakReason & BreakReason.AssemblyBreakpoint) > 0 || (breakReason & BreakReason.SourceCodeBreakpoint) > 0) - break; - if ((breakReason & BreakReason.SourceCode) > 0 && (engine.InvocationStack.Count == invocationStackCount && engine.CurrentScriptHash == prevScriptHash || engine.InvocationStack.Count < invocationStackCount)) + if ((breakReason & BreakReason.AssemblyBreakpoint) > 0) break; + if ((breakReason & BreakReason.SourceCodeBreakpoint) > 0 + || (breakReason & BreakReason.SourceCode) > 0) + { + uint currentInstructionPointer = (uint)engine.CurrentContext!.InstructionPointer; + if (currentInstructionPointer <= prevInstructionPointer) + break; + if (engine.InvocationStack.Count != prevInvocationStackCount) + break; + SourceFilenameAndLineNum currentSourceCode = contractScriptHashToAllInstructionPointerToSourceLineNum[engine.CurrentScriptHash][currentInstructionPointer]; + if (currentSourceCode.sourceFilename == prevSourceCode.sourceFilename + && currentSourceCode.lineNum != prevSourceCode.lineNum) + break; + // Do not break when invocation stack count is same as prev, + // and current source code is the same as prev, + // and instruction pointer is greater than prev + } engine.State = VMState.NONE; } }