diff --git a/source/java/src/org/lucee/extension/debugger/coreinject/NativeDebuggerListener.java b/source/java/src/org/lucee/extension/debugger/coreinject/NativeDebuggerListener.java index 616cbb1..149e895 100644 --- a/source/java/src/org/lucee/extension/debugger/coreinject/NativeDebuggerListener.java +++ b/source/java/src/org/lucee/extension/debugger/coreinject/NativeDebuggerListener.java @@ -247,14 +247,23 @@ private static void rebuildBreakpointBounds() { /** * Stepping state for a single thread. + * + * startFile/startLine guard STEP_OVER against multi-expression source lines: + * Lucee instruments per statement, so a single source line can fire + * shouldSuspend several times. Without a line check, step-over re-stops + * on the same source line each time. */ private static class StepState { final StepMode mode; final int startDepth; + final String startFile; + final int startLine; - StepState(StepMode mode, int startDepth) { + StepState(StepMode mode, int startDepth, String startFile, int startLine) { this.mode = mode; this.startDepth = startDepth; + this.startFile = startFile; + this.startLine = startLine; } } @@ -632,9 +641,11 @@ private static boolean consumePauseRequest(long threadId) { * @param threadId The Java thread ID * @param mode The step mode (STEP_INTO, STEP_OVER, STEP_OUT) * @param currentDepth The current stack depth when stepping started + * @param startFile File the thread is currently suspended at (used by STEP_OVER line guard) + * @param startLine Line the thread is currently suspended at (used by STEP_OVER line guard) */ - public static void startStepping(long threadId, StepMode mode, int currentDepth) { - steppingThreads.put(threadId, new StepState(mode, currentDepth)); + public static void startStepping(long threadId, StepMode mode, int currentDepth, String startFile, int startLine) { + steppingThreads.put(threadId, new StepState(mode, currentDepth, startFile, startLine)); updateHasSuspendConditions(); Log.debug("Start stepping: thread=" + threadId + " mode=" + mode + " depth=" + currentDepth); } @@ -956,8 +967,14 @@ public static boolean shouldSuspend(PageContext pc, String file, int line) { return true; case STEP_OVER: - // Stop when at same or shallower depth - return currentDepth <= stepState.startDepth; + // Shallower than start: a frame popped, stop. + if (currentDepth < stepState.startDepth) return true; + // Deeper than start: we're inside a callee, keep running. + if (currentDepth > stepState.startDepth) return false; + // Same depth: only stop when we've actually moved to a new source line. + // Without this guard a multi-expression line (e.g. `a = b & c`) re-stops + // on each sub-expression instrumentation point. + return line != stepState.startLine || !file.equals(stepState.startFile); case STEP_OUT: // Stop when shallower than start depth diff --git a/source/java/src/org/lucee/extension/debugger/coreinject/NativeLuceeVm.java b/source/java/src/org/lucee/extension/debugger/coreinject/NativeLuceeVm.java index 0e99a83..6522300 100644 --- a/source/java/src/org/lucee/extension/debugger/coreinject/NativeLuceeVm.java +++ b/source/java/src/org/lucee/extension/debugger/coreinject/NativeLuceeVm.java @@ -404,22 +404,25 @@ public void continueAll() { @Override public void stepIn(long threadID) { - int currentDepth = getStackDepthForThread(threadID); - NativeDebuggerListener.startStepping(threadID, StepMode.STEP_INTO, currentDepth); - continue_(threadID); + startStep(threadID, StepMode.STEP_INTO); } @Override public void stepOver(long threadID) { - int currentDepth = getStackDepthForThread(threadID); - NativeDebuggerListener.startStepping(threadID, StepMode.STEP_OVER, currentDepth); - continue_(threadID); + startStep(threadID, StepMode.STEP_OVER); } @Override public void stepOut(long threadID) { + startStep(threadID, StepMode.STEP_OUT); + } + + private void startStep(long threadID, StepMode mode) { int currentDepth = getStackDepthForThread(threadID); - NativeDebuggerListener.startStepping(threadID, StepMode.STEP_OUT, currentDepth); + NativeDebuggerListener.SuspendLocation loc = NativeDebuggerListener.getSuspendLocation(threadID); + String startFile = loc != null ? loc.file : null; + int startLine = loc != null ? loc.line : 0; + NativeDebuggerListener.startStepping(threadID, mode, currentDepth, startFile, startLine); continue_(threadID); } diff --git a/test/cfml/SteppingTest.cfc b/test/cfml/SteppingTest.cfc index 25183c6..bf6af48 100644 --- a/test/cfml/SteppingTest.cfc +++ b/test/cfml/SteppingTest.cfc @@ -87,6 +87,46 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="dap" { // ========== Step Over ========== + it( title="native: stepOver advances one line on multi-expression line", body=function() { + // Lucee instruments per statement, so a multi-expression source line + // (e.g. ``) fires shouldSuspend multiple times. + // Step-over must guard on (file,line) — not depth alone — or each + // click only consumes one sub-expression stop. + var multiTarget = getArtifactPath( "stepping-multiexpr-target.cfm" ); + var bpLine = 2; // simple line, breakpoint + var multiLine = 3; // multi-expression + var nextLine = 4; // target of second step + + dap.setBreakpoints( multiTarget, [ bpLine ] ); + triggerArtifact( "stepping-multiexpr-target.cfm" ); + + var stopped = dap.waitForEvent( "stopped", 2000 ); + var threadId = stopped.body.threadId; + + var frame = getTopFrame( threadId ); + expect( frame.line ).toBe( bpLine, "Should start at L#bpLine#" ); + + // Clear the breakpoint so subsequent stops can only come from stepping — + // otherwise the breakpoint check (which runs before the step check) would + // re-fire on each sub-expression at L#bpLine#. + clearBreakpoints( multiTarget ); + + // First step lands on the multi-expression line. + dap.stepOver( threadId ); + stopped = dap.waitForEvent( "stopped", 2000 ); + frame = getTopFrame( threadId ); + expect( frame.line ).toBe( multiLine, "First step should land on multi-expression L#multiLine#, got L#frame.line#" ); + + // Second step from the multi-expression line must advance to L#nextLine# + // in one click — not re-stop on L#multiLine# for the next sub-expression. + dap.stepOver( threadId ); + stopped = dap.waitForEvent( "stopped", 2000 ); + frame = getTopFrame( threadId ); + expect( frame.line ).toBe( nextLine, "Step over from multi-expression L#multiLine# should advance to L#nextLine# in one click, got L#frame.line#" ); + + cleanupThread( threadId ); + }, skip=notNativeMode() ); + it( "stepOver skips function call", function() { // Set breakpoint at call to outerFunc dap.setBreakpoints( variables.targetFile, [ lines.mainCallOuter ] ); diff --git a/test/cfml/artifacts/stepping-multiexpr-target.cfm b/test/cfml/artifacts/stepping-multiexpr-target.cfm new file mode 100644 index 0000000..5e6e59b --- /dev/null +++ b/test/cfml/artifacts/stepping-multiexpr-target.cfm @@ -0,0 +1,5 @@ + + + + +done: #var4#