[GR-59465] Fix disabling debugger stepping too aggressively.

PullRequest: graal/19238
This commit is contained in:
Allan Gregersen 2024-11-08 09:13:07 +00:00
commit d7f4612086
6 changed files with 44 additions and 8 deletions

View File

@ -498,4 +498,6 @@ public interface JDWPContext {
boolean isSingleSteppingDisabled();
Object allocateInstance(KlassRef klass);
void steppingInProgress(Thread t, boolean value);
}

View File

@ -204,6 +204,7 @@ public final class DebuggerController implements ContextsListener {
fine(() -> "Adding step command request in thread " + getThreadName(thread) + " with ID: " + commandRequestId);
SteppingInfo steppingInfo = new SteppingInfo(commandRequestId, suspendPolicy, isPopFrames, isForceEarlyReturn, stepKind);
commandRequestIds.put(thread, steppingInfo);
context.steppingInProgress(getContext().asHostThread(thread), true);
}
/**
@ -825,6 +826,7 @@ public final class DebuggerController implements ContextsListener {
if (steppingInfo != null) {
if (steppingInfo.isForceEarlyReturn()) {
fine(() -> "not suspending here due to force early return: " + event.getSourceSection());
context.steppingInProgress(hostThread, false);
return;
}
CallFrame[] callFrames = createCallFrames(ids.getIdAsLong(currentThread), event.getStackFrames(), 1, steppingInfo);
@ -860,14 +862,21 @@ public final class DebuggerController implements ContextsListener {
});
} else {
fine(() -> "step not completed - check for breakpoints");
continueStepping(event, steppingInfo, currentThread);
commandRequestIds.put(currentThread, steppingInfo);
result = checkForBreakpoints(event, jobs, currentThread, callFrames);
if (!result.breakpointHit) {
// no breakpoint
continueStepping(event, steppingInfo, currentThread);
commandRequestIds.put(currentThread, steppingInfo);
}
}
} else {
result = checkForBreakpoints(event, jobs, currentThread, callFrames);
}
if (!commandRequestIds.containsKey(currentThread)) {
// we're done stepping then
context.steppingInProgress(hostThread, false);
}
if (result.skipSuspend) {
return;
}

View File

@ -686,13 +686,17 @@ public final class EspressoLanguage extends TruffleLanguage<EspressoContext> {
public final class DisableSingleStepping implements AutoCloseable {
private final boolean steppingDisabled;
private DisableSingleStepping() {
getThreadLocalState().disableSingleStepping();
steppingDisabled = getThreadLocalState().disableSingleStepping(false);
}
@Override
public void close() {
getThreadLocalState().enableSingleStepping();
if (steppingDisabled) {
getThreadLocalState().enableSingleStepping();
}
}
}

View File

@ -43,6 +43,8 @@ public class EspressoThreadLocalState {
private int singleSteppingDisabledCounter;
private boolean stepInProgress;
@SuppressWarnings("unused")
public EspressoThreadLocalState(EspressoContext context) {
typeStack = new ClassRegistry.TypeStack();
@ -124,8 +126,16 @@ public class EspressoThreadLocalState {
return privilegedStack;
}
public void disableSingleStepping() {
singleSteppingDisabledCounter++;
public void setSteppingInProgress(boolean value) {
stepInProgress = value;
}
public boolean disableSingleStepping(boolean forceDisable) {
if (forceDisable || stepInProgress) {
singleSteppingDisabledCounter++;
return true;
}
return false;
}
public void enableSingleStepping() {

View File

@ -276,6 +276,17 @@ public final class JDWPContextImpl implements JDWPContext {
return context.getAllocator().createNew((ObjectKlass) klass);
}
@Override
public void steppingInProgress(Thread t, boolean value) {
Object previous = null;
try {
previous = controller.enterTruffleContext();
context.getLanguage().getThreadLocalStateFor(t).setSteppingInProgress(value);
} finally {
controller.leaveTruffleContext(previous);
}
}
@Override
public Object[] getAllGuestThreads() {
StaticObject[] activeThreads = context.getActiveThreads();

View File

@ -58,7 +58,7 @@ public final class Target_org_graalvm_continuations_ContinuationImpl {
// reflection or create the FrameRecords in the guest.
// Re-enabled in the catch clause of Continuation.resume0().
// TODO(GR-54326): Let Truffle Instrumentation know.
tls.disableSingleStepping();
tls.disableSingleStepping(true);
// This internal exception will be caught in BytecodeNode's interpreter loop. Frame records
// will be added to the exception object in a linked list until it's caught in resume below.
@ -96,7 +96,7 @@ public final class Target_org_graalvm_continuations_ContinuationImpl {
// Disable stepping until we have fully re-winded.
// Re-enabled in ResumeNextContinuationNode.dolast()
// TODO(GR-54326): Let Truffle Instrumentation know.
tls.disableSingleStepping();
tls.disableSingleStepping(true);
rewind.execute(stack);
// Normal completion.
return false;