Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
40 changes: 40 additions & 0 deletions test/cfml/SteppingTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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. `<cfset x = a & b>`) 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; // <cfset var2 = "b"> simple line, breakpoint
var multiLine = 3; // <cfset var3 = var1 & var2> multi-expression
var nextLine = 4; // <cfset var4 = var3 & var1> 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 ] );
Expand Down
5 changes: 5 additions & 0 deletions test/cfml/artifacts/stepping-multiexpr-target.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<cfset var1 = "a">
<cfset var2 = "b">
<cfset var3 = var1 & var2>
<cfset var4 = var3 & var1>
<cfoutput>done: #var4#</cfoutput>