Skip to content

Commit fecac30

Browse files
committed
fix disabling debugger stepping too aggressively
1 parent 0ce63ee commit fecac30

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/JDWPContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,6 @@ public interface JDWPContext {
498498
boolean isSingleSteppingDisabled();
499499

500500
Object allocateInstance(KlassRef klass);
501+
502+
void steppingInProgress(Thread t, boolean value);
501503
}

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/impl/DebuggerController.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public void setCommandRequestId(Object thread, int commandRequestId, byte suspen
204204
fine(() -> "Adding step command request in thread " + getThreadName(thread) + " with ID: " + commandRequestId);
205205
SteppingInfo steppingInfo = new SteppingInfo(commandRequestId, suspendPolicy, isPopFrames, isForceEarlyReturn, stepKind);
206206
commandRequestIds.put(thread, steppingInfo);
207+
context.steppingInProgress(getContext().asHostThread(thread), true);
207208
}
208209

209210
/**
@@ -825,6 +826,7 @@ public void onSuspend(SuspendedEvent event) {
825826
if (steppingInfo != null) {
826827
if (steppingInfo.isForceEarlyReturn()) {
827828
fine(() -> "not suspending here due to force early return: " + event.getSourceSection());
829+
context.steppingInProgress(hostThread, false);
828830
return;
829831
}
830832
CallFrame[] callFrames = createCallFrames(ids.getIdAsLong(currentThread), event.getStackFrames(), 1, steppingInfo);
@@ -860,14 +862,21 @@ public void onSuspend(SuspendedEvent event) {
860862
});
861863
} else {
862864
fine(() -> "step not completed - check for breakpoints");
863-
continueStepping(event, steppingInfo, currentThread);
864-
commandRequestIds.put(currentThread, steppingInfo);
865865

866866
result = checkForBreakpoints(event, jobs, currentThread, callFrames);
867+
if (!result.breakpointHit) {
868+
// no breakpoint
869+
continueStepping(event, steppingInfo, currentThread);
870+
commandRequestIds.put(currentThread, steppingInfo);
871+
}
867872
}
868873
} else {
869874
result = checkForBreakpoints(event, jobs, currentThread, callFrames);
870875
}
876+
if (!commandRequestIds.containsKey(currentThread)) {
877+
// we're done stepping then
878+
context.steppingInProgress(hostThread, false);
879+
}
871880
if (result.skipSuspend) {
872881
return;
873882
}

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoLanguage.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import com.oracle.truffle.api.staticobject.DefaultStaticProperty;
6060
import com.oracle.truffle.api.staticobject.StaticProperty;
6161
import com.oracle.truffle.api.staticobject.StaticShape;
62+
import com.oracle.truffle.espresso.classfile.JavaKind;
63+
import com.oracle.truffle.espresso.classfile.JavaVersion;
6264
import com.oracle.truffle.espresso.classfile.descriptors.Names;
6365
import com.oracle.truffle.espresso.classfile.descriptors.Signatures;
6466
import com.oracle.truffle.espresso.classfile.descriptors.StaticSymbols;
@@ -70,7 +72,6 @@
7072
import com.oracle.truffle.espresso.classfile.descriptors.Utf8ConstantTable;
7173
import com.oracle.truffle.espresso.impl.SuppressFBWarnings;
7274
import com.oracle.truffle.espresso.meta.EspressoError;
73-
import com.oracle.truffle.espresso.classfile.JavaKind;
7475
import com.oracle.truffle.espresso.nodes.commands.ExitCodeNode;
7576
import com.oracle.truffle.espresso.nodes.commands.GetBindingsNode;
7677
import com.oracle.truffle.espresso.nodes.commands.ReferenceProcessRootNode;
@@ -80,7 +81,6 @@
8081
import com.oracle.truffle.espresso.runtime.EspressoException;
8182
import com.oracle.truffle.espresso.runtime.EspressoThreadLocalState;
8283
import com.oracle.truffle.espresso.runtime.GuestAllocator;
83-
import com.oracle.truffle.espresso.classfile.JavaVersion;
8484
import com.oracle.truffle.espresso.runtime.OS;
8585
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;
8686
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject.StaticObjectFactory;
@@ -679,13 +679,17 @@ public DisableSingleStepping disableStepping() {
679679

680680
public final class DisableSingleStepping implements AutoCloseable {
681681

682+
private final boolean steppingDisabled;
683+
682684
private DisableSingleStepping() {
683-
getThreadLocalState().disableSingleStepping();
685+
steppingDisabled = getThreadLocalState().disableSingleStepping(false);
684686
}
685687

686688
@Override
687689
public void close() {
688-
getThreadLocalState().enableSingleStepping();
690+
if (steppingDisabled) {
691+
getThreadLocalState().enableSingleStepping();
692+
}
689693
}
690694
}
691695

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/EspressoThreadLocalState.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class EspressoThreadLocalState {
4343

4444
private int singleSteppingDisabledCounter;
4545

46+
private boolean stepInProgress;
47+
4648
@SuppressWarnings("unused")
4749
public EspressoThreadLocalState(EspressoContext context) {
4850
typeStack = new ClassRegistry.TypeStack();
@@ -124,8 +126,16 @@ public VM.PrivilegedStack getPrivilegedStack() {
124126
return privilegedStack;
125127
}
126128

127-
public void disableSingleStepping() {
128-
singleSteppingDisabledCounter++;
129+
public void setSteppingInProgress(boolean value) {
130+
stepInProgress = value;
131+
}
132+
133+
public boolean disableSingleStepping(boolean forceDisable) {
134+
if (forceDisable || stepInProgress) {
135+
singleSteppingDisabledCounter++;
136+
return true;
137+
}
138+
return false;
129139
}
130140

131141
public void enableSingleStepping() {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/JDWPContextImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ public Object allocateInstance(KlassRef klass) {
275275
return context.getAllocator().createNew((ObjectKlass) klass);
276276
}
277277

278+
@Override
279+
public void steppingInProgress(Thread t, boolean value) {
280+
Object previous = null;
281+
try {
282+
previous = controller.enterTruffleContext();
283+
context.getLanguage().getThreadLocalStateFor(t).setSteppingInProgress(value);
284+
} finally {
285+
controller.leaveTruffleContext(previous);
286+
}
287+
}
288+
278289
@Override
279290
public Object[] getAllGuestThreads() {
280291
StaticObject[] activeThreads = context.getActiveThreads();

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/Target_org_graalvm_continuations_ContinuationImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void suspend0(StaticObject self, @Inject EspressoLanguage language, @Inje
5858
// reflection or create the FrameRecords in the guest.
5959
// Re-enabled in the catch clause of Continuation.resume0().
6060
// TODO(GR-54326): Let Truffle Instrumentation know.
61-
tls.disableSingleStepping();
61+
tls.disableSingleStepping(true);
6262

6363
// This internal exception will be caught in BytecodeNode's interpreter loop. Frame records
6464
// will be added to the exception object in a linked list until it's caught in resume below.
@@ -96,7 +96,7 @@ static boolean resume0(StaticObject self,
9696
// Disable stepping until we have fully re-winded.
9797
// Re-enabled in ResumeNextContinuationNode.dolast()
9898
// TODO(GR-54326): Let Truffle Instrumentation know.
99-
tls.disableSingleStepping();
99+
tls.disableSingleStepping(true);
100100
rewind.execute(stack);
101101
// Normal completion.
102102
return false;

0 commit comments

Comments
 (0)