From 6487fdf9738b96a5f83395f0f2bd53e2896d4b2e Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Mon, 21 May 2018 18:39:47 +0300 Subject: [PATCH] IDEA-186951 Caller method filter - prepare caller key in advance --- .../debugger/engine/JavaExecutionStack.java | 10 ++++ .../breakpoints/BreakpointIntentionAction.kt | 48 ++++++------------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java b/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java index f658d377fceb..03a6c8c00b5a 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/JavaExecutionStack.java @@ -10,6 +10,7 @@ import com.intellij.debugger.jdi.StackFrameProxyImpl; import com.intellij.debugger.jdi.ThreadGroupReferenceProxyImpl; import com.intellij.debugger.jdi.ThreadReferenceProxyImpl; import com.intellij.debugger.memory.utils.StackFrameItem; +import com.intellij.debugger.ui.breakpoints.BreakpointIntentionAction; import com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint; import com.intellij.debugger.ui.impl.watch.MethodsTracker; import com.intellij.debugger.ui.impl.watch.StackFrameDescriptorImpl; @@ -23,6 +24,7 @@ import com.intellij.xdebugger.frame.XStackFrame; import com.intellij.xdebugger.impl.XDebugSessionImpl; import com.intellij.xdebugger.settings.XDebuggerSettingsManager; import com.sun.jdi.Location; +import com.sun.jdi.Method; import com.sun.jdi.ThreadReference; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -89,6 +91,14 @@ public class JavaExecutionStack extends XExecutionStack { @NotNull public XStackFrame createStackFrame(@NotNull StackFrameProxyImpl stackFrameProxy) { StackFrameDescriptorImpl descriptor = new StackFrameDescriptorImpl(stackFrameProxy, myTracker); + + if (descriptor.getUiIndex() == 1 && myTopFrame instanceof JavaStackFrame) { + Method method = descriptor.getMethod(); + if (method != null) { + ((JavaStackFrame)myTopFrame).getDescriptor().putUserData(BreakpointIntentionAction.CALLER_KEY, DebuggerUtilsEx.methodKey(method)); + } + } + DebugProcessImpl debugProcess = (DebugProcessImpl)descriptor.getDebugProcess(); Location location = descriptor.getLocation(); if (location != null) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointIntentionAction.kt b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointIntentionAction.kt index 1e894a609c24..05859b0102de 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointIntentionAction.kt +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointIntentionAction.kt @@ -3,13 +3,9 @@ package com.intellij.debugger.ui.breakpoints import com.intellij.debugger.engine.JavaDebugProcess import com.intellij.debugger.engine.JavaStackFrame -import com.intellij.debugger.engine.SuspendContextImpl -import com.intellij.debugger.engine.evaluation.EvaluateException -import com.intellij.debugger.engine.events.DebuggerContextCommandImpl -import com.intellij.debugger.impl.DebuggerUtilsEx -import com.intellij.debugger.impl.PrioritizedTask import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.util.Key import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.util.text.StringUtil import com.intellij.ui.classFilter.ClassFilter @@ -94,6 +90,9 @@ internal abstract class BreakpointIntentionAction(protected val myBreakpoint: XB } companion object { + @JvmField + val CALLER_KEY = Key.create("CALLER_KEY") + @JvmStatic fun getIntentions(breakpoint: XBreakpoint<*>, currentSession: XDebugSession?): List { val process = currentSession?.debugProcess @@ -102,43 +101,24 @@ internal abstract class BreakpointIntentionAction(protected val myBreakpoint: XB val currentStackFrame = currentSession.currentStackFrame if (currentStackFrame is JavaStackFrame) { - currentStackFrame.descriptor.typeName?.let { + val frameDescriptor = currentStackFrame.descriptor + frameDescriptor.typeName?.let { res.add(AddClassFilter(breakpoint, it)) res.add(AddClassNotFilter(breakpoint, it)) } - currentStackFrame.descriptor.thisObject?.uniqueID()?.let { + frameDescriptor.thisObject?.uniqueID()?.let { res.add(AddInstanceFilter(breakpoint, it)) } + + if (Registry.`is`("debugger.breakpoints.caller.filter")) { + frameDescriptor.getUserData(CALLER_KEY)?.let { + res.add(AddCallerFilter(breakpoint, it)) + res.add(AddCallerNotFilter(breakpoint, it)) + } + } } - if (Registry.`is`("debugger.breakpoints.caller.filter")) { - val debugProcess = process.debuggerSession.process - debugProcess.managerThread.invokeAndWait(object : DebuggerContextCommandImpl(debugProcess.debuggerContext) { - - override fun getPriority() = PrioritizedTask.Priority.HIGH - - override fun threadAction(suspendContext: SuspendContextImpl) { - try { - val thread = suspendContext.thread - if (thread != null && thread.frameCount() > 1) { - val parentFrame = thread.frame(1) - if (parentFrame != null) { - val method = DebuggerUtilsEx.getMethod(parentFrame.location()) - if (method != null) { - val key = DebuggerUtilsEx.methodKey(parentFrame.location().method()) - res.add(AddCallerFilter(breakpoint, key)) - res.add(AddCallerNotFilter(breakpoint, key)) - } - } - } - } - catch (e: EvaluateException) { - LineBreakpoint.LOG.warn(e) - } - } - }) - } return res } return emptyList()