From 3e69250f7277b8657e576bbc5a3a53fba0b00318 Mon Sep 17 00:00:00 2001 From: Vladimir Ilmov Date: Thu, 9 Jul 2020 20:23:55 +0200 Subject: [PATCH] (CoroutineDebugger) Restored frame variables isn't shown for 2020.1. #KT-40172 fixed --- .../data/coroutineStackFrameItems.kt | 11 ++++++++++- .../proxy/CoroutineLibraryAgent2Proxy.kt | 19 +++++++++++++------ .../proxy/mirror/coroutinesDebugMirror.kt | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/data/coroutineStackFrameItems.kt b/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/data/coroutineStackFrameItems.kt index d69db4cc07d..515b85274e8 100644 --- a/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/data/coroutineStackFrameItems.kt +++ b/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/data/coroutineStackFrameItems.kt @@ -51,7 +51,16 @@ class SuspendCoroutineStackFrameItem( val stackTraceElement: StackTraceElement, location: Location, spilledVariables: List = emptyList() -) : CoroutineStackFrameItem(location, spilledVariables) +) : CoroutineStackFrameItem(location, spilledVariables) { + override fun createFrame(debugProcess: DebugProcessImpl): XStackFrame? { + return debugProcess.invokeInManagerThread { + val frame = debugProcess.findFirstFrame() ?: return@invokeInManagerThread null + val locationFrame = LocationStackFrameProxyImpl(location, frame) + val position = location.findPosition(debugProcess.project) + CoroutineStackFrame(locationFrame, position, spilledVariables, includeFrameVariables = false) + } + } +} /** diff --git a/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/CoroutineLibraryAgent2Proxy.kt b/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/CoroutineLibraryAgent2Proxy.kt index 173ac5380ae..fb39ff7a3ac 100644 --- a/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/CoroutineLibraryAgent2Proxy.kt +++ b/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/CoroutineLibraryAgent2Proxy.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.idea.debugger.coroutine.proxy import com.intellij.xdebugger.frame.XNamedValue +import com.sun.jdi.ObjectReference import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineInfoData import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineNameIdState import org.jetbrains.kotlin.idea.debugger.coroutine.data.CreationCoroutineStackFrameItem @@ -32,11 +33,7 @@ class CoroutineLibraryAgent2Proxy(private val executionContext: DefaultExecution private fun mapToCoroutineInfoData(mirror: MirrorOfCoroutineInfo): CoroutineInfoData? { val coroutineNameIdState = CoroutineNameIdState.instance(mirror) val stackTrace = mirror.enhancedStackTrace?.mapNotNull { it.stackTraceElement() } ?: emptyList() - val variables: List = mirror.lastObservedFrame?.let { - val spilledVariables = debugMetadata?.baseContinuationImpl?.mirror(it, executionContext) - spilledVariables?.spilledValues(executionContext) - } ?: emptyList() - val stackFrames = findStackFrames(stackTrace, variables) + val stackFrames = findStackFrames(stackTrace, mirror.lastObservedFrame) return CoroutineInfoData( coroutineNameIdState, stackFrames.restoredStackFrames, @@ -57,14 +54,24 @@ class CoroutineLibraryAgent2Proxy(private val executionContext: DefaultExecution private fun findStackFrames( frames: List, - variables: List + lastObservedFrame: ObjectReference? ): CoroutineStackFrames { val index = frames.indexOfFirst { it.isCreationSeparatorFrame() } val restoredStackTraceElements = if (index >= 0) frames.take(index) else frames + + var observedFrame = lastObservedFrame val restoredStackFrames = restoredStackTraceElements.map { + val variables: List = observedFrame?.let { + val spilledVariables = debugMetadata?.baseContinuationImpl?.mirror(it, executionContext) + if (spilledVariables != null) { + observedFrame = spilledVariables.nextContinuation + spilledVariables.spilledValues(executionContext) + } else + null + } ?: emptyList() SuspendCoroutineStackFrameItem(it, locationCache.createLocation(it), variables) } val creationStackFrames = frames.subList(index + 1, frames.size).mapIndexed { ix, it -> diff --git a/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/mirror/coroutinesDebugMirror.kt b/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/mirror/coroutinesDebugMirror.kt index b2176ec315e..1391ab4eef8 100644 --- a/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/mirror/coroutinesDebugMirror.kt +++ b/idea/jvm-debugger/jvm-debugger-coroutine/src/org/jetbrains/kotlin/idea/debugger/coroutine/proxy/mirror/coroutinesDebugMirror.kt @@ -141,7 +141,7 @@ class CoroutineInfo private constructor( debugProbesImplMirror.enhanceStackTraceWithThreadDump(context, value, lastObservedStackTrace) else emptyList() val lastObservedThread = threadValue(value, lastObservedThreadField) - val lastObservedFrame = threadValue(value, lastObservedFrameField) + val lastObservedFrame = objectValue(value, lastObservedFrameField) return MirrorOfCoroutineInfo( value, coroutineContext,