do not create bpt requests for prepared classes if breakpoints were muted

This commit is contained in:
Egor.Ushakov
2016-10-27 11:55:14 +03:00
parent f2ca89d42b
commit b02ce376dd
6 changed files with 33 additions and 31 deletions
@@ -193,7 +193,7 @@ public class RequestManagerImpl extends DebugProcessAdapterImpl implements Reque
request.putProperty(REQUESTOR, requestor);
}
private void registerRequest(Requestor requestor, EventRequest request) {
public void registerRequest(Requestor requestor, EventRequest request) {
myRequestorToBelongedRequests.computeIfAbsent(requestor, r -> new HashSet<>()).add(request);
}
@@ -105,16 +105,20 @@ public abstract class Breakpoint<P extends JavaBreakpointProperties> implements
*/
public abstract void createRequest(DebugProcessImpl debugProcess);
protected boolean shouldCreateRequest(final DebugProcessImpl debugProcess) {
protected boolean shouldCreateRequest(DebugProcessImpl debugProcess, boolean forPreparedClass) {
return ApplicationManager.getApplication().runReadAction((Computable<Boolean>)() -> {
JavaDebugProcess process = debugProcess.getXdebugProcess();
return process != null
&& debugProcess.isAttached()
&& ((XDebugSessionImpl)process.getSession()).isBreakpointActive(myXBreakpoint)
&& debugProcess.getRequestsManager().findRequests(this).isEmpty();
&& (forPreparedClass || debugProcess.getRequestsManager().findRequests(this).isEmpty());
});
}
protected boolean shouldCreateRequest(DebugProcessImpl debugProcess) {
return shouldCreateRequest(debugProcess, false);
}
/**
* Request for creating all needed JPDA requests in the specified VM
* @param debuggerProcess the requesting process
@@ -294,12 +294,12 @@ public abstract class BreakpointWithHighlighter<P extends JavaBreakpointProperti
}
@Override
public void processClassPrepare(final DebugProcess debugProcess, final ReferenceType classType) {
if (!isEnabled() || !isValid()) {
return;
public void processClassPrepare(DebugProcess debugProcess, ReferenceType classType) {
DebugProcessImpl process = (DebugProcessImpl)debugProcess;
if (shouldCreateRequest(process, true)) {
createRequestForPreparedClass(process, classType);
updateUI();
}
createRequestForPreparedClass((DebugProcessImpl)debugProcess, classType);
updateUI();
}
/**
@@ -140,19 +140,18 @@ public class ExceptionBreakpoint extends Breakpoint<JavaExceptionBreakpointPrope
public void processClassPrepare(DebugProcess process, ReferenceType refType) {
DebugProcessImpl debugProcess = (DebugProcessImpl)process;
if (!isEnabled()) {
return;
}
// trying to create a request
RequestManagerImpl manager = debugProcess.getRequestsManager();
manager.enableRequest(manager.createExceptionRequest(this, refType, isNotifyCaught(), isNotifyUncaught()));
if (shouldCreateRequest(debugProcess, true)) {
// trying to create a request
RequestManagerImpl manager = debugProcess.getRequestsManager();
manager.enableRequest(manager.createExceptionRequest(this, refType, isNotifyCaught(), isNotifyUncaught()));
if (LOG.isDebugEnabled()) {
if (refType != null) {
LOG.debug("Created exception request for reference type " + refType.name());
}
else {
LOG.debug("Created exception request for reference type null");
if (LOG.isDebugEnabled()) {
if (refType != null) {
LOG.debug("Created exception request for reference type " + refType.name());
}
else {
LOG.debug("Created exception request for reference type null");
}
}
}
}
@@ -58,6 +58,7 @@ import com.sun.jdi.request.ClassPrepareRequest;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.MethodEntryRequest;
import com.sun.jdi.request.MethodExitRequest;
import one.util.streamex.StreamEx;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -69,7 +70,6 @@ import org.jetbrains.org.objectweb.asm.Opcodes;
import javax.swing.*;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
public class MethodBreakpoint extends BreakpointWithHighlighter<JavaMethodBreakpointProperties> {
@@ -132,12 +132,14 @@ public class MethodBreakpoint extends BreakpointWithHighlighter<JavaMethodBreakp
private void createRequestForSubClasses(@NotNull DebugProcessImpl debugProcess, @NotNull ReferenceType baseType) {
DebuggerManagerThreadImpl.assertIsManagerThread();
ClassPrepareRequest request = debugProcess.getRequestsManager().createClassPrepareRequest((debuggerProcess, referenceType) -> {
RequestManagerImpl requestsManager = debugProcess.getRequestsManager();
ClassPrepareRequest request = requestsManager.createClassPrepareRequest((debuggerProcess, referenceType) -> {
if (instanceOf(referenceType, baseType)) {
createRequestForPreparedClassEmulated(debugProcess, referenceType, false);
}
}, null);
if (request != null) {
requestsManager.registerRequest(this, request);
request.enable();
}
@@ -145,6 +147,9 @@ public class MethodBreakpoint extends BreakpointWithHighlighter<JavaMethodBreakp
}
private void createRequestForPreparedClassEmulated(@NotNull DebugProcessImpl debugProcess, @NotNull ReferenceType classType, boolean base) {
if (!base && !shouldCreateRequest(debugProcess, true)) {
return;
}
try {
for (Method method : classType.methods()) {
if (getMethodName().equals(method.name()) && mySignature.getName(debugProcess).equals(method.signature())) {
@@ -420,13 +425,7 @@ public class MethodBreakpoint extends BreakpointWithHighlighter<JavaMethodBreakp
@Nullable
static <T extends EventRequest> T findRequest(@NotNull DebugProcessImpl debugProcess, Class<T> requestClass, Requestor requestor) {
Set<EventRequest> requests = debugProcess.getRequestsManager().findRequests(requestor);
for (EventRequest eventRequest : requests) {
if (eventRequest.getClass().equals(requestClass)) {
return (T)eventRequest;
}
}
return null;
return StreamEx.of(debugProcess.getRequestsManager().findRequests(requestor)).select(requestClass).findFirst().orElse(null);
}
@Override
@@ -147,7 +147,7 @@ public class RunToCursorBreakpoint extends LineBreakpoint<JavaLineBreakpointProp
}
@Override
protected boolean shouldCreateRequest(DebugProcessImpl debugProcess) {
return debugProcess.isAttached() && debugProcess.getRequestsManager().findRequests(this).isEmpty();
protected boolean shouldCreateRequest(DebugProcessImpl debugProcess, boolean forPreparedClass) {
return debugProcess.isAttached() && (forPreparedClass || debugProcess.getRequestsManager().findRequests(this).isEmpty());
}
}