Skip to content
Merged
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
8 changes: 4 additions & 4 deletions com.microsoft.java.debug.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.epfl.scala</groupId>
<artifactId>com-microsoft-java-debug-core</artifactId>
<artifactId>com.microsoft.java.debug.core</artifactId>
<packaging>jar</packaging>
<name>${base.name} :: Debugger Core</name>
<description>The Java Debug Server is an implementation of Visual Studio Code (VSCode) Debug Protocol. It can be used in Visual Studio Code to debug Java programs.</description>
<url>https://github.com/Microsoft/java-debug</url>
<version>0.34.0+1-SNAPSHOT</version>
<url>https://github.com/scalacenter/java-debug</url>
<version>0.38.0</version>
<properties>
<base.name>Java Debug Server for Visual Studio Code</base.name>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -33,7 +33,7 @@
</developers>

<organization>
<name>ch.epfl.scaal</name>
<name>ch.epfl.scala</name>
<url>https://scala.epfl.ch/</url>
</organization>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2020 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/

package com.microsoft.java.debug.core.adapter;

import com.microsoft.java.debug.core.protocol.Requests;
import com.sun.jdi.Method;

public interface IStepFilterProvider extends IProvider {
boolean skip(Method method, Requests.StepFilters filters);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/

package com.microsoft.java.debug.core.adapter;

import com.microsoft.java.debug.core.protocol.Requests;
import com.sun.jdi.Method;
import org.apache.commons.lang3.ArrayUtils;

public class StepFilterProvider implements IStepFilterProvider {
@Override
public boolean skip(Method method, Requests.StepFilters filters) {
if (!isConfigured(filters)) {
return false;
}
return (filters.skipStaticInitializers && method.isStaticInitializer())
|| (filters.skipSynthetics && method.isSynthetic())
|| (filters.skipConstructors && method.isConstructor());
}

private boolean isConfigured(Requests.StepFilters filters) {
if (filters == null) {
return false;
}
return ArrayUtils.isNotEmpty(filters.allowClasses) || ArrayUtils.isNotEmpty(filters.skipClasses)
|| ArrayUtils.isNotEmpty(filters.classNameFilters) || filters.skipConstructors
|| filters.skipStaticInitializers || filters.skipSynthetics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.apache.commons.lang3.ArrayUtils;

import com.microsoft.java.debug.core.DebugEvent;
import com.microsoft.java.debug.core.DebugUtility;
import com.microsoft.java.debug.core.IDebugSession;
Expand All @@ -26,12 +24,12 @@
import com.microsoft.java.debug.core.adapter.ErrorCode;
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
import com.microsoft.java.debug.core.adapter.IStepFilterProvider;
import com.microsoft.java.debug.core.protocol.Events;
import com.microsoft.java.debug.core.protocol.Messages.Response;
import com.microsoft.java.debug.core.protocol.Requests.Arguments;
import com.microsoft.java.debug.core.protocol.Requests.Command;
import com.microsoft.java.debug.core.protocol.Requests.StepArguments;
import com.microsoft.java.debug.core.protocol.Requests.StepFilters;
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.Location;
import com.sun.jdi.Method;
Expand Down Expand Up @@ -161,27 +159,26 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
} else if (event instanceof StepEvent) {
ThreadReference thread = ((StepEvent) event).thread();
threadState.deleteStepRequest(eventRequestManager);
if (isStepFiltersConfigured(context.getStepFilters())) {
try {
if (threadState.pendingStepType == Command.STEPIN) {
int currentStackDepth = thread.frameCount();
Location currentStepLocation = getTopFrame(thread).location();
IStepFilterProvider stepFilter = context.getProvider(IStepFilterProvider.class);
try {
if (threadState.pendingStepType == Command.STEPIN) {
int currentStackDepth = thread.frameCount();
Location currentStepLocation = getTopFrame(thread).location();

// If the ending step location is filtered, or same as the original location where the step into operation is originated,
// do another step of the same kind.
if (shouldFilterLocation(threadState.stepLocation, currentStepLocation, context)
|| shouldDoExtraStepInto(threadState.stackDepth, threadState.stepLocation, currentStackDepth, currentStepLocation)) {
threadState.pendingStepRequest = DebugUtility.createStepIntoRequest(thread,
context.getStepFilters().allowClasses,
context.getStepFilters().skipClasses);
threadState.pendingStepRequest.enable();
debugEvent.shouldResume = true;
return;
}
// If the ending step location is filtered, or same as the original location where the step into operation is originated,
// do another step of the same kind.
if (shouldFilterLocation(threadState.stepLocation, currentStepLocation, stepFilter, context)
|| shouldDoExtraStepInto(threadState.stackDepth, threadState.stepLocation, currentStackDepth, currentStepLocation)) {
threadState.pendingStepRequest = DebugUtility.createStepIntoRequest(thread,
context.getStepFilters().allowClasses,
context.getStepFilters().skipClasses);
threadState.pendingStepRequest.enable();
debugEvent.shouldResume = true;
return;
}
} catch (IncompatibleThreadStateException | IndexOutOfBoundsException ex) {
// ignore.
}
} catch (IncompatibleThreadStateException | IndexOutOfBoundsException ex) {
// ignore.
}
threadState.deleteMethodExitRequest(eventRequestManager);
if (threadState.eventSubscription != null) {
Expand All @@ -205,33 +202,19 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
}
}

private boolean isStepFiltersConfigured(StepFilters filters) {
if (filters == null) {
return false;
}
return ArrayUtils.isNotEmpty(filters.allowClasses) || ArrayUtils.isNotEmpty(filters.skipClasses)
|| ArrayUtils.isNotEmpty(filters.classNameFilters) || filters.skipConstructors
|| filters.skipStaticInitializers || filters.skipSynthetics;
}

/**
* Return true if the StepEvent's location is a Method that the user has indicated to filter.
*
* @throws IncompatibleThreadStateException
* if the thread is not suspended in the target VM.
*/
private boolean shouldFilterLocation(Location originalLocation, Location currentLocation, IDebugAdapterContext context)
private boolean shouldFilterLocation(Location originalLocation, Location currentLocation, IStepFilterProvider stepFilter, IDebugAdapterContext context)
throws IncompatibleThreadStateException {
if (originalLocation == null || currentLocation == null) {
return false;
}
return !shouldFilterMethod(originalLocation.method(), context) && shouldFilterMethod(currentLocation.method(), context);
}

private boolean shouldFilterMethod(Method method, IDebugAdapterContext context) {
return (context.getStepFilters().skipStaticInitializers && method.isStaticInitializer())
|| (context.getStepFilters().skipSynthetics && method.isSynthetic())
|| (context.getStepFilters().skipConstructors && method.isConstructor());
return !stepFilter.skip(originalLocation.method(), context.getStepFilters())
&& stepFilter.skip(currentLocation.method(), context.getStepFilters());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion com.microsoft.java.debug.plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<version>2.11.0</version>
</artifactItem>
<artifactItem>
<groupId>com.microsoft.java</groupId>
<groupId>ch.epfl.scala</groupId>
<artifactId>com.microsoft.java.debug.core</artifactId>
<version>0.38.0</version>
</artifactItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import com.microsoft.java.debug.core.adapter.IHotCodeReplaceProvider;
import com.microsoft.java.debug.core.adapter.IProviderContext;
import com.microsoft.java.debug.core.adapter.ISourceLookUpProvider;
import com.microsoft.java.debug.core.adapter.IStepFilterProvider;
import com.microsoft.java.debug.core.adapter.IVirtualMachineManagerProvider;
import com.microsoft.java.debug.core.adapter.ProviderContext;
import com.microsoft.java.debug.core.adapter.StepFilterProvider;
import com.microsoft.java.debug.plugin.internal.eval.JdtEvaluationProvider;

/**
Expand All @@ -35,6 +37,7 @@ public static IProviderContext createProviderContext() {
context.registerProvider(IHotCodeReplaceProvider.class, new JavaHotCodeReplaceProvider());
context.registerProvider(IEvaluationProvider.class, new JdtEvaluationProvider());
context.registerProvider(ICompletionsProvider.class, new CompletionsProvider());
context.registerProvider(IStepFilterProvider.class, new StepFilterProvider());

return context;
}
Expand Down