Skip to content

Commit d7f4612

Browse files
committed
[GR-59465] Fix disabling debugger stepping too aggressively.
PullRequest: graal/19238
2 parents 2c9935c + fecac30 commit d7f4612

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,17 @@ public DisableSingleStepping disableStepping() {
686686

687687
public final class DisableSingleStepping implements AutoCloseable {
688688

689+
private final boolean steppingDisabled;
690+
689691
private DisableSingleStepping() {
690-
getThreadLocalState().disableSingleStepping();
692+
steppingDisabled = getThreadLocalState().disableSingleStepping(false);
691693
}
692694

693695
@Override
694696
public void close() {
695-
getThreadLocalState().enableSingleStepping();
697+
if (steppingDisabled) {
698+
getThreadLocalState().enableSingleStepping();
699+
}
696700
}
697701
}
698702

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
@@ -276,6 +276,17 @@ public Object allocateInstance(KlassRef klass) {
276276
return context.getAllocator().createNew((ObjectKlass) klass);
277277
}
278278

279+
@Override
280+
public void steppingInProgress(Thread t, boolean value) {
281+
Object previous = null;
282+
try {
283+
previous = controller.enterTruffleContext();
284+
context.getLanguage().getThreadLocalStateFor(t).setSteppingInProgress(value);
285+
} finally {
286+
controller.leaveTruffleContext(previous);
287+
}
288+
}
289+
279290
@Override
280291
public Object[] getAllGuestThreads() {
281292
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)