Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support step filters when stepping #106

Merged
merged 23 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
07ec2c3
Init commit for step filter
testforstephen Nov 10, 2017
61dfc24
Add debug filter options in launch.json
testforstephen Nov 14, 2017
24cb8c7
Refactor config names
testforstephen Nov 14, 2017
6036641
fix javadoc
testforstephen Nov 14, 2017
00086a0
remove unused JDIMethod
testforstephen Nov 15, 2017
c1475c2
Merge branch 'master' into jinbo_stepfilter
testforstephen Nov 15, 2017
ce91adc
Merge branch 'master' of github.com:Microsoft/java-debug into jinbo_s…
testforstephen Nov 15, 2017
45faae5
Merge branch 'master' into jinbo_stepfilter
yaohaizh Nov 17, 2017
6b1002c
resolve merge conflicts
testforstephen Nov 22, 2017
586d83b
Merge branch 'jinbo_stepfilter' of github.com:Microsoft/java-debug in…
testforstephen Nov 22, 2017
7878d81
Remove unnecessary blank space
testforstephen Nov 22, 2017
86e3b4a
Merge branch 'master' into jinbo_stepfilter
testforstephen Nov 22, 2017
d6023f3
Refactor step handler to a standalone StepRequestHandler
testforstephen Nov 23, 2017
0656a3c
Merge branch 'jinbo_stepfilter' of github.com:Microsoft/java-debug in…
testforstephen Nov 23, 2017
c9cc031
resolve merge conflicts
testforstephen Nov 24, 2017
af7d6ee
Add logic to clean up stale thread states and step request
testforstephen Nov 27, 2017
6431ce9
fix review comments
testforstephen Nov 28, 2017
fdc62f1
Fix the concurrent issue for step request
testforstephen Nov 28, 2017
6ed3189
Use stateless StepRequestHandler to avoid concurrent issue
testforstephen Nov 29, 2017
3fa4aed
resolve merge conflicts
testforstephen Dec 4, 2017
9e4968b
Merge branch 'master' into jinbo_stepfilter
testforstephen Dec 5, 2017
0e4efdb
Merge branch 'master' into jinbo_stepfilter
akaroml Dec 6, 2017
a91a16a
Resolve review comments
testforstephen Dec 6, 2017
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 @@ -24,7 +24,6 @@

import org.apache.commons.lang3.StringUtils;

import com.sun.jdi.Location;
import com.sun.jdi.Method;
import com.sun.jdi.ObjectCollectedException;
import com.sun.jdi.ThreadReference;
Expand All @@ -37,7 +36,6 @@
import com.sun.jdi.connect.LaunchingConnector;
import com.sun.jdi.connect.VMStartException;
import com.sun.jdi.event.MethodEntryEvent;
import com.sun.jdi.event.StepEvent;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.EventRequestManager;
import com.sun.jdi.request.MethodEntryRequest;
Expand Down Expand Up @@ -192,67 +190,52 @@ public static IDebugSession attach(VirtualMachineManager vmManager, String hostN
}

/**
* Steps over newly pushed frames.
*
* Create a step over request on the specified thread.
* @param thread
* the target thread.
* @param eventHub
* the {@link IEventHub} instance.
* @return the new {@link Location} of the execution flow of the specified
* thread.
* the target thread.
* @param stepFilters
* the step filters when stepping.
* @return the new step request.
*/
public static CompletableFuture<Location> stepOver(ThreadReference thread, IEventHub eventHub) {
return DebugUtility.step(thread, eventHub, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
public static StepRequest createStepOverRequest(ThreadReference thread, String[] stepFilters) {
return createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER, stepFilters);
}

/**
* Steps into newly pushed frames.
*
* Create a step into request on the specified thread.
* @param thread
* the target thread.
* @param eventHub
* the {@link IEventHub} instance.
* @return the new {@link Location} of the execution flow of the specified
* thread.
* the target thread.
* @param stepFilters
* the step filters when stepping.
* @return the new step request.
*/
public static CompletableFuture<Location> stepInto(ThreadReference thread, IEventHub eventHub) {
return DebugUtility.step(thread, eventHub, StepRequest.STEP_LINE, StepRequest.STEP_INTO);
public static StepRequest createStepIntoRequest(ThreadReference thread, String[] stepFilters) {
return createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_INTO, stepFilters);
}

/**
* Steps out of the current frame.
*
* Create a step out request on the specified thread.
* @param thread
* the target thread.
* @param eventHub
* the {@link IEventHub} instance.
* @return the new {@link Location} of the execution flow of the specified
* thread.
* the target thread.
* @param stepFilters
* the step filters when stepping.
* @return the new step request.
*/
public static CompletableFuture<Location> stepOut(ThreadReference thread, IEventHub eventHub) {
return DebugUtility.step(thread, eventHub, StepRequest.STEP_LINE, StepRequest.STEP_OUT);
public static StepRequest createStepOutRequest(ThreadReference thread, String[] stepFilters) {
return createStepRequest(thread, StepRequest.STEP_LINE, StepRequest.STEP_OUT, stepFilters);
}

private static CompletableFuture<Location> step(ThreadReference thread, IEventHub eventHub, int stepSize,
int stepDepth) {
CompletableFuture<Location> future = new CompletableFuture<>();

StepRequest request = thread.virtualMachine().eventRequestManager().createStepRequest(thread, stepSize,
stepDepth);

eventHub.stepEvents().filter(debugEvent -> request.equals(debugEvent.event.request())).take(1)
.subscribe(debugEvent -> {
StepEvent event = (StepEvent) debugEvent.event;
future.complete(event.location());
deleteEventRequestSafely(thread.virtualMachine().eventRequestManager(), request);
});
private static StepRequest createStepRequest(ThreadReference thread, int stepSize, int stepDepth, String[] stepFilters) {
StepRequest request = thread.virtualMachine().eventRequestManager().createStepRequest(thread, stepSize, stepDepth);
if (stepFilters != null) {
for (String stepFilter : stepFilters) {
request.addClassExclusionFilter(stepFilter);
}
}
request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
request.addCountFilter(1);
request.enable();

thread.resume();

return future;
return request;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.microsoft.java.debug.core.adapter.handler.SetVariableRequestHandler;
import com.microsoft.java.debug.core.adapter.handler.SourceRequestHandler;
import com.microsoft.java.debug.core.adapter.handler.StackTraceRequestHandler;
import com.microsoft.java.debug.core.adapter.handler.StepRequestHandler;
import com.microsoft.java.debug.core.adapter.handler.ThreadsRequestHandler;
import com.microsoft.java.debug.core.adapter.handler.VariablesRequestHandler;
import com.microsoft.java.debug.core.protocol.IProtocolServer;
Expand Down Expand Up @@ -97,6 +98,7 @@ private void initialize() {
registerHandler(new SetExceptionBreakpointsRequestHandler());
registerHandler(new SourceRequestHandler());
registerHandler(new ThreadsRequestHandler());
registerHandler(new StepRequestHandler());
registerHandler(new StackTraceRequestHandler());
registerHandler(new ScopesRequestHandler());
registerHandler(new VariablesRequestHandler());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.microsoft.java.debug.core.adapter.variables.IVariableFormatter;
import com.microsoft.java.debug.core.adapter.variables.VariableFormatterFactory;
import com.microsoft.java.debug.core.protocol.IProtocolServer;
import com.microsoft.java.debug.core.protocol.Requests.StepFilters;

public class DebugAdapterContext implements IDebugAdapterContext {
private static final int MAX_CACHE_ITEMS = 10000;
Expand All @@ -38,6 +39,7 @@ public class DebugAdapterContext implements IDebugAdapterContext {
private transient boolean vmTerminated;
private boolean isVmStopOnEntry = false;
private String mainClass;
private StepFilters stepFilters;

private IdCollection<String> sourceReferences = new IdCollection<>();
private RecyclableObjectPool<Long, Object> recyclableIdPool = new RecyclableObjectPool<>();
Expand Down Expand Up @@ -212,4 +214,14 @@ public void setMainClass(String mainClass) {
public String getMainClass() {
return this.mainClass;
}

@Override
public void setStepFilters(StepFilters stepFilters) {
this.stepFilters = stepFilters;
}

@Override
public StepFilters getStepFilters() {
return stepFilters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public enum ErrorCode {
EMPTY_DEBUG_SESSION(1011),
INVALID_ENCODING(1012),
VM_TERMINATED(1013),
LAUNCH_IN_TERMINAL_FAILURE(1014);
LAUNCH_IN_TERMINAL_FAILURE(1014),
STEP_FAILURE(1015);

private int id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.microsoft.java.debug.core.IDebugSession;
import com.microsoft.java.debug.core.adapter.variables.IVariableFormatter;
import com.microsoft.java.debug.core.protocol.IProtocolServer;
import com.microsoft.java.debug.core.protocol.Requests.StepFilters;

public interface IDebugAdapterContext {
IProtocolServer getProtocolServer();
Expand Down Expand Up @@ -94,4 +95,8 @@ public interface IDebugAdapterContext {
void setMainClass(String mainClass);

String getMainClass();

void setStepFilters(StepFilters stepFilters);

StepFilters getStepFilters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
context.setAttached(true);
context.setSourcePaths(attachArguments.sourcePaths);
context.setDebuggeeEncoding(StandardCharsets.UTF_8); // Use UTF-8 as debuggee's default encoding format.
context.setStepFilters(attachArguments.stepFilters);

IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
context.getProtocolServer().sendEvent(new Events.StoppedEvent("breakpoint", bpThread.uniqueID()));
debugEvent.shouldResume = false;
}
} else if (event instanceof StepEvent) {
ThreadReference stepThread = ((StepEvent) event).thread();
context.getProtocolServer().sendEvent(new Events.StoppedEvent("step", stepThread.uniqueID()));
debugEvent.shouldResume = false;
} else if (event instanceof ExceptionEvent) {
ThreadReference thread = ((ExceptionEvent) event).thread();
context.getProtocolServer().sendEvent(new Events.StoppedEvent("exception", thread.uniqueID()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
context.setSourcePaths(launchArguments.sourcePaths);
context.setVmStopOnEntry(launchArguments.stopOnEntry);
context.setMainClass(parseMainClassWithoutModuleName(launchArguments.mainClass));
context.setStepFilters(launchArguments.stepFilters);

if (StringUtils.isBlank(launchArguments.encoding)) {
context.setDebuggeeEncoding(StandardCharsets.UTF_8);
Expand Down
Loading