Skip to content
Open
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 @@ -203,6 +203,15 @@ public void setAsync(boolean async) {
this.async = async;
}

@Override
public void setSuspendPolicy(String policy) {
}

@Override
public String getSuspendPolicy() {
return DebugSettings.getCurrent().suspendAllThreads ? "SUSPEND_ALL" : "SUSPEND_EVENT_THREAD";
}

@Override
public CompletableFuture<IBreakpoint> install() {
// It's possible that different class loaders create new class with the same name.
Expand Down Expand Up @@ -412,7 +421,11 @@ private CompletableFuture<List<BreakpointRequest>> createBreakpointRequests(List

newLocations.forEach(location -> {
BreakpointRequest request = vm.eventRequestManager().createBreakpointRequest(location);
request.setSuspendPolicy(BreakpointRequest.SUSPEND_EVENT_THREAD);
if ("SUSPEND_ALL".equals(getSuspendPolicy())) {
request.setSuspendPolicy(BreakpointRequest.SUSPEND_ALL);
} else {
request.setSuspendPolicy(BreakpointRequest.SUSPEND_EVENT_THREAD);
}
if (hitCount > 0) {
request.addCountFilter(hitCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public final class DebugSettings {
public int jdwpRequestTimeout = 3000;
public AsyncMode asyncJDWP = AsyncMode.OFF;
public Switch debugSupportOnDecompiledSource = Switch.OFF;
public boolean suspendAllThreads = false;

public static DebugSettings getCurrent() {
return current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ default void setAsync(boolean async) {
default boolean async() {
return false;
}

default void setSuspendPolicy(String policy) {
}

default String getSuspendPolicy() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.microsoft.java.debug.core.AsyncJdwpUtils;
import com.microsoft.java.debug.core.DebugEvent;
import com.microsoft.java.debug.core.DebugSettings;
import com.microsoft.java.debug.core.DebugUtility;
import com.microsoft.java.debug.core.IDebugSession;
import com.microsoft.java.debug.core.JdiExceptionReference;
Expand All @@ -48,6 +49,7 @@
import com.sun.jdi.StackFrame;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.Value;
import com.sun.jdi.VMDisconnectedException;
import com.sun.jdi.VoidValue;
import com.sun.jdi.event.BreakpointEvent;
import com.sun.jdi.event.Event;
Expand Down Expand Up @@ -112,8 +114,16 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
threadState.pendingStepRequest = DebugUtility.createStepOverRequest(thread, null);
}

if (DebugSettings.getCurrent().suspendAllThreads) {
threadState.pendingStepRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
}

threadState.pendingMethodExitRequest = thread.virtualMachine().eventRequestManager().createMethodExitRequest();
threadState.pendingMethodExitRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
if (DebugSettings.getCurrent().suspendAllThreads) {
threadState.pendingMethodExitRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
} else {
threadState.pendingMethodExitRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
}

threadState.targetStepIn = targetId > 0
? (MethodInvocation) context.getRecyclableIdPool().getObjectById(targetId) : null;
Expand Down Expand Up @@ -189,7 +199,15 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
}

context.getThreadCache().removeEventThread(thread.uniqueID());
DebugUtility.resumeThread(thread);
if (DebugSettings.getCurrent().suspendAllThreads) {
try {
context.getDebugSession().resume();
} catch (VMDisconnectedException e) {
// ignore
}
} else {
DebugUtility.resumeThread(thread);
}
ThreadsRequestHandler.checkThreadRunningAndRecycleIds(thread, context);
} catch (IncompatibleThreadStateException ex) {
// Roll back the Exception info if stepping fails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.lang3.StringUtils;

import com.microsoft.java.debug.core.AsyncJdwpUtils;
import com.microsoft.java.debug.core.DebugSettings;
import com.microsoft.java.debug.core.DebugUtility;
import com.microsoft.java.debug.core.adapter.AdapterUtils;
import com.microsoft.java.debug.core.adapter.ErrorCode;
Expand Down Expand Up @@ -149,6 +150,11 @@ private CompletableFuture<Response> resume(Requests.ContinueArguments arguments,
if (thread == null) {
thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId);
}

if (DebugSettings.getCurrent().suspendAllThreads) {
thread = null;
}

/**
* See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(),
* suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must
Expand Down