Skip to content

Commit 845119b

Browse files
committed
feat: support suspend all setting
1 parent 9623b8f commit 845119b

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/Breakpoint.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ public void setAsync(boolean async) {
203203
this.async = async;
204204
}
205205

206+
@Override
207+
public void setSuspendPolicy(String policy) {
208+
}
209+
210+
@Override
211+
public String getSuspendPolicy() {
212+
return DebugSettings.getCurrent().suspendAllThreads ? "SUSPEND_ALL" : "SUSPEND_EVENT_THREAD";
213+
}
214+
206215
@Override
207216
public CompletableFuture<IBreakpoint> install() {
208217
// It's possible that different class loaders create new class with the same name.
@@ -412,7 +421,11 @@ private CompletableFuture<List<BreakpointRequest>> createBreakpointRequests(List
412421

413422
newLocations.forEach(location -> {
414423
BreakpointRequest request = vm.eventRequestManager().createBreakpointRequest(location);
415-
request.setSuspendPolicy(BreakpointRequest.SUSPEND_EVENT_THREAD);
424+
if ("SUSPEND_ALL".equals(getSuspendPolicy())) {
425+
request.setSuspendPolicy(BreakpointRequest.SUSPEND_ALL);
426+
} else {
427+
request.setSuspendPolicy(BreakpointRequest.SUSPEND_EVENT_THREAD);
428+
}
416429
if (hitCount > 0) {
417430
request.addCountFilter(hitCount);
418431
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/DebugSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public final class DebugSettings {
4545
public int jdwpRequestTimeout = 3000;
4646
public AsyncMode asyncJDWP = AsyncMode.OFF;
4747
public Switch debugSupportOnDecompiledSource = Switch.OFF;
48+
public boolean suspendAllThreads = false;
4849

4950
public static DebugSettings getCurrent() {
5051
return current;

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/IBreakpoint.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@ default void setAsync(boolean async) {
5555
default boolean async() {
5656
return false;
5757
}
58+
59+
default void setSuspendPolicy(String policy) {
60+
}
61+
62+
default String getSuspendPolicy() {
63+
return null;
64+
}
5865
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/StepRequestHandler.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.microsoft.java.debug.core.AsyncJdwpUtils;
2424
import com.microsoft.java.debug.core.DebugEvent;
25+
import com.microsoft.java.debug.core.DebugSettings;
2526
import com.microsoft.java.debug.core.DebugUtility;
2627
import com.microsoft.java.debug.core.IDebugSession;
2728
import com.microsoft.java.debug.core.JdiExceptionReference;
@@ -48,6 +49,7 @@
4849
import com.sun.jdi.StackFrame;
4950
import com.sun.jdi.ThreadReference;
5051
import com.sun.jdi.Value;
52+
import com.sun.jdi.VMDisconnectedException;
5153
import com.sun.jdi.VoidValue;
5254
import com.sun.jdi.event.BreakpointEvent;
5355
import com.sun.jdi.event.Event;
@@ -112,8 +114,16 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
112114
threadState.pendingStepRequest = DebugUtility.createStepOverRequest(thread, null);
113115
}
114116

117+
if (DebugSettings.getCurrent().suspendAllThreads) {
118+
threadState.pendingStepRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
119+
}
120+
115121
threadState.pendingMethodExitRequest = thread.virtualMachine().eventRequestManager().createMethodExitRequest();
116-
threadState.pendingMethodExitRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
122+
if (DebugSettings.getCurrent().suspendAllThreads) {
123+
threadState.pendingMethodExitRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
124+
} else {
125+
threadState.pendingMethodExitRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
126+
}
117127

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

191201
context.getThreadCache().removeEventThread(thread.uniqueID());
192-
DebugUtility.resumeThread(thread);
202+
if (DebugSettings.getCurrent().suspendAllThreads) {
203+
try {
204+
context.getDebugSession().resume();
205+
} catch (VMDisconnectedException e) {
206+
// ignore
207+
}
208+
} else {
209+
DebugUtility.resumeThread(thread);
210+
}
193211
ThreadsRequestHandler.checkThreadRunningAndRecycleIds(thread, context);
194212
} catch (IncompatibleThreadStateException ex) {
195213
// Roll back the Exception info if stepping fails.

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/ThreadsRequestHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.commons.lang3.StringUtils;
2424

2525
import com.microsoft.java.debug.core.AsyncJdwpUtils;
26+
import com.microsoft.java.debug.core.DebugSettings;
2627
import com.microsoft.java.debug.core.DebugUtility;
2728
import com.microsoft.java.debug.core.adapter.AdapterUtils;
2829
import com.microsoft.java.debug.core.adapter.ErrorCode;
@@ -149,6 +150,11 @@ private CompletableFuture<Response> resume(Requests.ContinueArguments arguments,
149150
if (thread == null) {
150151
thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId);
151152
}
153+
154+
if (DebugSettings.getCurrent().suspendAllThreads) {
155+
thread = null;
156+
}
157+
152158
/**
153159
* See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(),
154160
* suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must

0 commit comments

Comments
 (0)