(CoroutineDebugger) StackFrameInterceptor service added to KotlinPositionManager, dependency cleanup
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(":idea:jvm-debugger:jvm-debugger-core"))
|
||||
implementation(project(":idea:jvm-debugger:jvm-debugger-core"))
|
||||
|
||||
compileOnly(toolsJarApi())
|
||||
compileOnly(intellijDep())
|
||||
|
||||
+3
-2
@@ -13,6 +13,8 @@ import com.sun.jdi.*
|
||||
import org.jetbrains.kotlin.idea.debugger.*
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineStackFrameItem
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.proxy.AsyncStackTraceContext
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.BaseExecutionContext
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.DefaultExecutionContext
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.ExecutionContext
|
||||
|
||||
class CoroutineAsyncStackTraceProvider : AsyncStackTraceProvider {
|
||||
@@ -38,8 +40,7 @@ class CoroutineAsyncStackTraceProvider : AsyncStackTraceProvider {
|
||||
if (threadReference == null || !threadReference.isSuspended || !canRunEvaluation(suspendContext))
|
||||
return defaultResult
|
||||
|
||||
val evaluationContext = EvaluationContextImpl(suspendContext as SuspendContextImpl, frameProxy)
|
||||
val context = ExecutionContext(evaluationContext, frameProxy)
|
||||
val context = DefaultExecutionContext(suspendContext as SuspendContextImpl, frameProxy)
|
||||
val astContext = AsyncStackTraceContext(context, method)
|
||||
return astContext.getAsyncStackTraceIfAny()
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.debugger.coroutine
|
||||
|
||||
import com.intellij.debugger.actions.AsyncStacksToggleAction
|
||||
import com.intellij.debugger.engine.DebugProcessImpl
|
||||
import com.intellij.debugger.engine.SuspendContextImpl
|
||||
import com.intellij.debugger.jdi.StackFrameProxyImpl
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.xdebugger.frame.XStackFrame
|
||||
import com.intellij.xdebugger.impl.XDebugSessionImpl
|
||||
import com.sun.jdi.Location
|
||||
import org.jetbrains.kotlin.idea.debugger.StackFrameInterceptor
|
||||
|
||||
class CoroutineStackFrameInterceptor(val project: Project) : StackFrameInterceptor {
|
||||
override fun createStackFrame(frame: StackFrameProxyImpl, debugProcess: DebugProcessImpl, location: Location): XStackFrame? =
|
||||
null
|
||||
}
|
||||
+2
-1
@@ -5,7 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.debugger.coroutine.data
|
||||
|
||||
import com.sun.jdi.*
|
||||
import com.sun.jdi.ObjectReference
|
||||
import com.sun.jdi.ThreadReference
|
||||
|
||||
/**
|
||||
* Represents state of a coroutine.
|
||||
|
||||
+5
-5
@@ -19,11 +19,12 @@ import org.jetbrains.kotlin.idea.debugger.coroutine.util.logger
|
||||
import org.jetbrains.kotlin.idea.debugger.SUSPEND_LAMBDA_CLASSES
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineStackFrameItem
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.DefaultCoroutineStackFrameItem
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.DefaultExecutionContext
|
||||
import org.jetbrains.kotlin.idea.debugger.isSubtype
|
||||
import org.jetbrains.kotlin.idea.debugger.safeVisibleVariableByName
|
||||
|
||||
class AsyncStackTraceContext(
|
||||
val context: ExecutionContext,
|
||||
val context: DefaultExecutionContext,
|
||||
val method: Method
|
||||
) {
|
||||
val log by logger
|
||||
@@ -46,13 +47,12 @@ class AsyncStackTraceContext(
|
||||
private fun locateContinuation(): ObjectReference? {
|
||||
val continuation: ObjectReference?
|
||||
if (isInvokeSuspendMethod(method)) {
|
||||
continuation = context.frameProxy.thisObject() ?: return null
|
||||
continuation = context.frameProxy?.thisObject() ?: return null
|
||||
if (!isSuspendLambda(continuation.referenceType()))
|
||||
return null
|
||||
} else if (isContinuationProvider(method)) {
|
||||
val frameProxy = context.frameProxy
|
||||
val continuationVariable = frameProxy.safeVisibleVariableByName(CONTINUATION_VARIABLE_NAME) ?: return null
|
||||
continuation = frameProxy.getValue(continuationVariable) as? ObjectReference ?: return null
|
||||
val continuationVariable = context.frameProxy?.safeVisibleVariableByName(CONTINUATION_VARIABLE_NAME) ?: return null
|
||||
continuation = context.frameProxy?.getValue(continuationVariable) as? ObjectReference ?: return null
|
||||
context.keepReference(continuation)
|
||||
} else {
|
||||
continuation = null
|
||||
|
||||
+5
-5
@@ -13,12 +13,13 @@ import org.jetbrains.kotlin.idea.debugger.coroutine.command.CoroutineBuilder
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineInfoCache
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineInfoData
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.util.logger
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.DefaultExecutionContext
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.ExecutionContext
|
||||
|
||||
class CoroutineDebugProbesProxy(val suspendContext: XSuspendContext) {
|
||||
private val log by logger
|
||||
|
||||
private var executionContext: ExecutionContext = executionContext()
|
||||
private var executionContext: DefaultExecutionContext = executionContext()
|
||||
// might want to use inner class but also having to monitor order of fields
|
||||
private var refs: ProcessReferences = ProcessReferences(executionContext)
|
||||
|
||||
@@ -185,16 +186,15 @@ class CoroutineDebugProbesProxy(val suspendContext: XSuspendContext) {
|
||||
private fun sizeOf(args: ObjectReference): Int =
|
||||
(executionContext.invokeMethod(args, refs.sizeRef, emptyList()) as IntegerValue).value()
|
||||
|
||||
private fun executionContext() : ExecutionContext {
|
||||
val evaluationContextImpl = EvaluationContextImpl(suspendContext as SuspendContextImpl, suspendContext.frameProxy)
|
||||
return ExecutionContext(evaluationContextImpl, suspendContext.frameProxy as StackFrameProxyImpl)
|
||||
private fun executionContext() : DefaultExecutionContext {
|
||||
return DefaultExecutionContext(suspendContext as SuspendContextImpl, suspendContext.frameProxy)
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO refactor later
|
||||
* Holds ClassTypes, Methods, ObjectReferences and Fields for a particular jvm
|
||||
*/
|
||||
class ProcessReferences(executionContext: ExecutionContext) {
|
||||
class ProcessReferences(executionContext: DefaultExecutionContext) {
|
||||
// kotlinx.coroutines.debug.DebugProbes instance and methods
|
||||
val debugProbesClsRef = executionContext.findClass("$DEBUG_PACKAGE.DebugProbes") as ClassType
|
||||
val debugProbesImplClsRef = executionContext.findClass("$DEBUG_PACKAGE.internal.DebugProbesImpl") as ClassType
|
||||
|
||||
+5
-6
@@ -6,17 +6,16 @@
|
||||
package org.jetbrains.kotlin.idea.debugger.coroutine.proxy
|
||||
|
||||
import com.sun.jdi.*
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineInfoData
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.ExecutionContext
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.DefaultExecutionContext
|
||||
import org.jetbrains.kotlin.idea.debugger.isSubtype
|
||||
|
||||
class LookupContinuation(val context: ExecutionContext, val frame: StackTraceElement) {
|
||||
class LookupContinuation(val context: DefaultExecutionContext, val frame: StackTraceElement) {
|
||||
|
||||
private fun suspendOrInvokeSuspend(method: Method): Boolean =
|
||||
"Lkotlin/coroutines/Continuation;)" in method.signature() ||
|
||||
(method.name() == "invokeSuspend" && method.signature() == "(Ljava/lang/Object;)Ljava/lang/Object;") // suspend fun or invokeSuspend
|
||||
(method.name() == "invokeSuspend" && method.signature() == "(Ljava/lang/Object;)Ljava/lang/Object;") // suspend fun or invokeSuspend
|
||||
|
||||
private fun findMethod() : Method {
|
||||
private fun findMethod(): Method {
|
||||
val clazz = context.findClass(frame.className) as ClassType
|
||||
val method = clazz.methodsByName(frame.methodName).last {
|
||||
val loc = it.location().lineNumber()
|
||||
@@ -75,7 +74,7 @@ class LookupContinuation(val context: ExecutionContext, val frame: StackTraceEle
|
||||
* Finds previous Continuation for this Continuation (completion field in BaseContinuationImpl)
|
||||
* @return null if given ObjectReference is not a BaseContinuationImpl instance or completion is null
|
||||
*/
|
||||
private fun getNextFrame(continuation: ObjectReference, context: ExecutionContext): ObjectReference? {
|
||||
private fun getNextFrame(continuation: ObjectReference, context: DefaultExecutionContext): ObjectReference? {
|
||||
val type = continuation.type() as ClassType
|
||||
if (!type.isSubtype("kotlin.coroutines.jvm.internal.BaseContinuationImpl")) return null
|
||||
val next = type.concreteMethodByName("getCompletion", "()Lkotlin/coroutines/Continuation;")
|
||||
|
||||
+2
-1
@@ -24,7 +24,8 @@ fun getPosition(stackTraceElement: StackTraceElement, project: Project): XSource
|
||||
@Suppress("DEPRECATION")
|
||||
psiFacade.findClass(
|
||||
stackTraceElement.className.substringBefore("$"), // find outer class, for which psi exists TODO
|
||||
GlobalSearchScope.everythingScope(project))
|
||||
GlobalSearchScope.everythingScope(project)
|
||||
)
|
||||
}
|
||||
|
||||
val classFile = psiClass?.containingFile?.virtualFile
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ interface XDebugSessionListenerProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Logger instantiation sample: 'val log by logger'
|
||||
* Logger instantiation: 'val log by logger'
|
||||
*/
|
||||
val logger: ReadOnlyProperty<Any, Logger> get() = LoggerDelegate()
|
||||
|
||||
|
||||
+8
-7
@@ -9,7 +9,6 @@ import com.intellij.debugger.engine.DebugProcessImpl
|
||||
import com.intellij.debugger.engine.JavaDebugProcess
|
||||
import com.intellij.debugger.engine.JavaExecutionStack
|
||||
import com.intellij.debugger.engine.SuspendContextImpl
|
||||
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl
|
||||
import com.intellij.debugger.jdi.StackFrameProxyImpl
|
||||
import com.intellij.debugger.jdi.ThreadReferenceProxyImpl
|
||||
import com.intellij.ide.CommonActionsManager
|
||||
@@ -46,12 +45,15 @@ import org.jetbrains.kotlin.idea.debugger.coroutine.CoroutineDebuggerContentInfo
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.CoroutineDebuggerContentInfo.Companion.XCOROUTINE_POPUP_ACTION_GROUP
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.VersionedImplementationProvider
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.*
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.proxy.*
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.proxy.ApplicationThreadExecutor
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.proxy.CoroutineDebugProbesProxy
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.proxy.LookupContinuation
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.proxy.ManagerThreadExecutor
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.util.CreateContentParams
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.util.CreateContentParamsProvider
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.util.XDebugSessionListenerProvider
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.util.logger
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.ExecutionContext
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.DefaultExecutionContext
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.event.KeyAdapter
|
||||
import java.awt.event.KeyEvent
|
||||
@@ -363,13 +365,12 @@ class XCoroutineView(val project: Project, val session: XDebugSession) :
|
||||
return XDebuggerUtil.getInstance().createPosition(classFile, lineNumber)
|
||||
}
|
||||
|
||||
private fun executionContext(suspendContext: SuspendContextImpl, frameProxy: StackFrameProxyImpl): ExecutionContext {
|
||||
val evaluationContextImpl = EvaluationContextImpl(suspendContext, frameProxy)
|
||||
return ExecutionContext(evaluationContextImpl, frameProxy)
|
||||
private fun executionContext(suspendContext: SuspendContextImpl, frameProxy: StackFrameProxyImpl): DefaultExecutionContext {
|
||||
return DefaultExecutionContext(suspendContext, frameProxy)
|
||||
}
|
||||
|
||||
private fun createSyntheticStackFrame(
|
||||
executionContext: ExecutionContext,
|
||||
executionContext: DefaultExecutionContext,
|
||||
frame: SuspendCoroutineStackFrameItem
|
||||
): SyntheticStackFrame? {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user