Skip to content

Commit

Permalink
improve StepOverSourceCode
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Aug 14, 2024
1 parent 04eea0f commit 9f30c1c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Fairy.Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 9f30c1c

Please sign in to comment.