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 @@ -42,24 +42,28 @@ public class Breakpoint implements IBreakpoint {
private String condition = null;
private String logMessage = null;
private HashMap<Object, Object> propertyMap = new HashMap<>();
private final boolean suspendAllThreads;

private boolean async = false;

Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber) {
this(vm, eventHub, className, lineNumber, 0, null);
Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, boolean suspendAllThreads) {
this(vm, eventHub, className, lineNumber, 0, null, suspendAllThreads);
}

Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount) {
this(vm, eventHub, className, lineNumber, hitCount, null);
Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount, boolean suspendAllThreads) {
this(vm, eventHub, className, lineNumber, hitCount, null, suspendAllThreads);
}

Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount, String condition) {
this(vm, eventHub, className, lineNumber, hitCount, condition, null);
Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount,
String condition, boolean suspendAllThreads) {
this(vm, eventHub, className, lineNumber, hitCount, condition, null, suspendAllThreads);
}

Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount, String condition, String logMessage) {
Breakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount,
String condition, String logMessage, boolean suspendAllThreads) {
this.vm = vm;
this.eventHub = eventHub;
this.suspendAllThreads = suspendAllThreads;
String contextClass = className;
String methodName = null;
String methodSignature = null;
Expand All @@ -79,13 +83,15 @@ public class Breakpoint implements IBreakpoint {
this.logMessage = logMessage;
}

Breakpoint(VirtualMachine vm, IEventHub eventHub, JavaBreakpointLocation sourceLocation, int hitCount, String condition, String logMessage) {
Breakpoint(VirtualMachine vm, IEventHub eventHub, JavaBreakpointLocation sourceLocation, int hitCount,
String condition, String logMessage, boolean suspendAllThreads) {
this.vm = vm;
this.eventHub = eventHub;
this.sourceLocation = sourceLocation;
this.hitCount = hitCount;
this.condition = condition;
this.logMessage = logMessage;
this.suspendAllThreads = suspendAllThreads;
}

// IDebugResource
Expand Down Expand Up @@ -203,6 +209,19 @@ public void setAsync(boolean async) {
this.async = async;
}

@Override
public void setSuspendPolicy(String policy) {
}

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

protected boolean suspendAllThreads() {
return suspendAllThreads;
}

@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 +431,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 @@ -36,9 +36,12 @@ public class DebugSession implements IDebugSession {
private EventHub eventHub = new EventHub();
private List<EventRequest> eventRequests = new ArrayList<>();
private List<Disposable> subscriptions = new ArrayList<>();
private final boolean suspendAllThreads;

public DebugSession(VirtualMachine virtualMachine) {
vm = virtualMachine;
// Capture suspend policy at session start - this persists for the session lifetime
this.suspendAllThreads = DebugSettings.getCurrent().suspendAllThreads;
}

@Override
Expand Down Expand Up @@ -128,17 +131,17 @@ public void terminate() {

@Override
public IBreakpoint createBreakpoint(JavaBreakpointLocation sourceLocation, int hitCount, String condition, String logMessage) {
return new EvaluatableBreakpoint(vm, this.getEventHub(), sourceLocation, hitCount, condition, logMessage);
return new EvaluatableBreakpoint(vm, this.getEventHub(), sourceLocation, hitCount, condition, logMessage, suspendAllThreads);
}

@Override
public IBreakpoint createBreakpoint(String className, int lineNumber, int hitCount, String condition, String logMessage) {
return new EvaluatableBreakpoint(vm, this.getEventHub(), className, lineNumber, hitCount, condition, logMessage);
return new EvaluatableBreakpoint(vm, this.getEventHub(), className, lineNumber, hitCount, condition, logMessage, suspendAllThreads);
}

@Override
public IWatchpoint createWatchPoint(String className, String fieldName, String accessType, String condition, int hitCount) {
return new Watchpoint(vm, this.getEventHub(), className, fieldName, accessType, condition, hitCount);
return new Watchpoint(vm, this.getEventHub(), className, fieldName, accessType, condition, hitCount, suspendAllThreads);
}

@Override
Expand Down Expand Up @@ -260,10 +263,15 @@ public VirtualMachine getVM() {
return vm;
}

@Override
public boolean suspendAllThreads() {
return suspendAllThreads;
}

@Override
public IMethodBreakpoint createFunctionBreakpoint(String className, String functionName, String condition,
int hitCount) {
return new MethodBreakpoint(vm, this.getEventHub(), className, functionName, condition, hitCount);
return new MethodBreakpoint(vm, this.getEventHub(), className, functionName, condition, hitCount, suspendAllThreads);
}

private void createExceptionBreakpoint(ReferenceType refType, boolean notifyCaught, boolean notifyUncaught,
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 @@ -394,6 +394,7 @@ private static StepRequest createStepRequest(ThreadReference thread, int stepSiz
request.addClassExclusionFilter(exclusionFilter);
}
}
// Note: suspend policy will be set by the caller (StepRequestHandler) based on session settings
request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
request.addCountFilter(1);

Expand All @@ -415,7 +416,7 @@ public static CompletableFuture<Long> stopOnEntry(IDebugSession debugSession, St
EventRequestManager manager = debugSession.getVM().eventRequestManager();
MethodEntryRequest request = manager.createMethodEntryRequest();
request.addClassFilter(mainClass);
request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
request.setSuspendPolicy(debugSession.suspendAllThreads() ? EventRequest.SUSPEND_ALL : EventRequest.SUSPEND_EVENT_THREAD);

debugSession.getEventHub().events().filter(debugEvent -> {
return debugEvent.event instanceof MethodEntryEvent && request.equals(debugEvent.event.request());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ public class EvaluatableBreakpoint extends Breakpoint implements IEvaluatableBre
private Object compiledLogpointExpression = null;
private Map<Long, Object> compiledExpressions = new ConcurrentHashMap<>();

EvaluatableBreakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber) {
this(vm, eventHub, className, lineNumber, 0, null);
EvaluatableBreakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, boolean suspendAllThreads) {
this(vm, eventHub, className, lineNumber, 0, null, suspendAllThreads);
}

EvaluatableBreakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount) {
this(vm, eventHub, className, lineNumber, hitCount, null);
EvaluatableBreakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount, boolean suspendAllThreads) {
this(vm, eventHub, className, lineNumber, hitCount, null, suspendAllThreads);
}

EvaluatableBreakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount,
String condition) {
this(vm, eventHub, className, lineNumber, hitCount, condition, null);
String condition, boolean suspendAllThreads) {
this(vm, eventHub, className, lineNumber, hitCount, condition, null, suspendAllThreads);
}

EvaluatableBreakpoint(VirtualMachine vm, IEventHub eventHub, String className, int lineNumber, int hitCount,
String condition, String logMessage) {
super(vm, eventHub, className, lineNumber, hitCount, condition, logMessage);
String condition, String logMessage, boolean suspendAllThreads) {
super(vm, eventHub, className, lineNumber, hitCount, condition, logMessage, suspendAllThreads);
this.eventHub = eventHub;
}

EvaluatableBreakpoint(VirtualMachine vm, IEventHub eventHub, JavaBreakpointLocation sourceLocation, int hitCount,
String condition, String logMessage) {
super(vm, eventHub, sourceLocation, hitCount, condition, logMessage);
String condition, String logMessage, boolean suspendAllThreads) {
super(vm, eventHub, sourceLocation, hitCount, condition, logMessage, suspendAllThreads);
this.eventHub = eventHub;
}

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 @@ -52,4 +52,10 @@ void setExceptionBreakpoints(boolean notifyCaught, boolean notifyUncaught, Strin
IEventHub getEventHub();

VirtualMachine getVM();

/**
* Returns whether breakpoints should suspend all threads or just the event thread.
* This value is captured at session start and persists for the session lifetime.
*/
boolean suspendAllThreads();
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class MethodBreakpoint implements IMethodBreakpoint, IEvaluatableBreakpoi
private String condition;
private int hitCount;
private boolean async = false;
private final boolean suspendAllThreads;

private HashMap<Object, Object> propertyMap = new HashMap<>();
private Object compiledConditionalExpression = null;
Expand All @@ -53,7 +54,7 @@ public class MethodBreakpoint implements IMethodBreakpoint, IEvaluatableBreakpoi
private List<Disposable> subscriptions = new ArrayList<>();

public MethodBreakpoint(VirtualMachine vm, IEventHub eventHub, String className, String functionName,
String condition, int hitCount) {
String condition, int hitCount, boolean suspendAllThreads) {
Objects.requireNonNull(vm);
Objects.requireNonNull(eventHub);
Objects.requireNonNull(className);
Expand All @@ -64,6 +65,7 @@ public MethodBreakpoint(VirtualMachine vm, IEventHub eventHub, String className,
this.functionName = functionName;
this.condition = condition;
this.hitCount = hitCount;
this.suspendAllThreads = suspendAllThreads;
}

@Override
Expand Down Expand Up @@ -262,7 +264,7 @@ private Optional<MethodEntryRequest> createMethodEntryRequest0(ReferenceType typ
MethodEntryRequest request = vm.eventRequestManager().createMethodEntryRequest();

request.addClassFilter(type);
request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
request.setSuspendPolicy(suspendAllThreads ? EventRequest.SUSPEND_ALL : EventRequest.SUSPEND_EVENT_THREAD);
if (hitCount > 0) {
request.addCountFilter(hitCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@ public class Watchpoint implements IWatchpoint, IEvaluatableBreakpoint {
private HashMap<Object, Object> propertyMap = new HashMap<>();
private Object compiledConditionalExpression = null;
private Map<Long, Object> compiledExpressions = new ConcurrentHashMap<>();
private final boolean suspendAllThreads;

// IDebugResource
private List<EventRequest> requests = new ArrayList<>();
private List<Disposable> subscriptions = new ArrayList<>();

Watchpoint(VirtualMachine vm, IEventHub eventHub, String className, String fieldName) {
this(vm, eventHub, className, fieldName, "write");
Watchpoint(VirtualMachine vm, IEventHub eventHub, String className, String fieldName, boolean suspendAllThreads) {
this(vm, eventHub, className, fieldName, "write", suspendAllThreads);
}

Watchpoint(VirtualMachine vm, IEventHub eventHub, String className, String fieldName, String accessType) {
this(vm, eventHub, className, fieldName, accessType, null, 0);
Watchpoint(VirtualMachine vm, IEventHub eventHub, String className, String fieldName, String accessType, boolean suspendAllThreads) {
this(vm, eventHub, className, fieldName, accessType, null, 0, suspendAllThreads);
}

Watchpoint(VirtualMachine vm, IEventHub eventHub, String className, String fieldName, String accessType, String condition, int hitCount) {
Watchpoint(VirtualMachine vm, IEventHub eventHub, String className, String fieldName, String accessType,
String condition, int hitCount, boolean suspendAllThreads) {
Objects.requireNonNull(vm);
Objects.requireNonNull(eventHub);
Objects.requireNonNull(className);
Expand All @@ -71,6 +73,7 @@ public class Watchpoint implements IWatchpoint, IEvaluatableBreakpoint {
this.accessType = accessType;
this.condition = condition;
this.hitCount = hitCount;
this.suspendAllThreads = suspendAllThreads;
}

@Override
Expand Down Expand Up @@ -212,7 +215,7 @@ private List<WatchpointRequest> createWatchpointRequests(ReferenceType type) {
}

watchpointRequests.forEach(request -> {
request.setSuspendPolicy(WatchpointRequest.SUSPEND_EVENT_THREAD);
request.setSuspendPolicy(suspendAllThreads ? EventRequest.SUSPEND_ALL : EventRequest.SUSPEND_EVENT_THREAD);
if (hitCount > 0) {
request.addCountFilter(hitCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.sun.jdi.event.ThreadStartEvent;
import com.sun.jdi.event.VMDeathEvent;
import com.sun.jdi.event.VMDisconnectEvent;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.event.VMStartEvent;

public class ConfigurationDoneRequestHandler implements IDebugRequestHandler {
Expand Down Expand Up @@ -119,7 +120,9 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
((ExceptionEvent) event).catchLocation() == null);
context.getExceptionManager().setException(thread.uniqueID(), jdiException);
context.getThreadCache().addEventThread(thread, "exception");
context.getProtocolServer().sendEvent(new Events.StoppedEvent("exception", thread.uniqueID()));
boolean allThreadsStopped = event.request() != null
&& event.request().suspendPolicy() == EventRequest.SUSPEND_ALL;
context.getProtocolServer().sendEvent(new Events.StoppedEvent("exception", thread.uniqueID(), allThreadsStopped));
debugEvent.shouldResume = false;
} else {
isImportantEvent = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.StackFrame;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.StepRequest;

/**
Expand Down Expand Up @@ -121,7 +122,8 @@ private void stepInto(IDebugAdapterContext context, ThreadReference thread) {
debugEvent.shouldResume = false;
// Have to send two events to keep the UI sync with the step in operations:
context.getProtocolServer().sendEvent(new Events.ContinuedEvent(thread.uniqueID()));
context.getProtocolServer().sendEvent(new Events.StoppedEvent("restartframe", thread.uniqueID()));
boolean allThreadsStopped = request.suspendPolicy() == EventRequest.SUSPEND_ALL;
context.getProtocolServer().sendEvent(new Events.StoppedEvent("restartframe", thread.uniqueID(), allThreadsStopped));
context.getThreadCache().setThreadStoppedReason(thread.uniqueID(), "restartframe");
});
request.enable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,19 @@ private void registerBreakpointHandler(IDebugAdapterContext context) {
debugEvent.eventSet.resume();
} else {
context.getThreadCache().addEventThread(bpThread, breakpointName);
boolean allThreadsStopped = event.request() != null
&& event.request().suspendPolicy() == EventRequest.SUSPEND_ALL;
context.getProtocolServer().sendEvent(new Events.StoppedEvent(
breakpointName, bpThread.uniqueID()));
breakpointName, bpThread.uniqueID(), allThreadsStopped));
}
});
});
} else {
context.getThreadCache().addEventThread(bpThread, breakpointName);
boolean allThreadsStopped = event.request() != null
&& event.request().suspendPolicy() == EventRequest.SUSPEND_ALL;
context.getProtocolServer().sendEvent(new Events.StoppedEvent(
breakpointName, bpThread.uniqueID()));
breakpointName, bpThread.uniqueID(), allThreadsStopped));
}
debugEvent.shouldResume = false;
}
Expand Down
Loading