Debugger: Gracefully handle debugger exceptions we can't do anything reasonable with (EA-128154, EA-139473)
This commit is contained in:
+1
-21
@@ -25,8 +25,6 @@ class KotlinCoroutinesAsyncStackTraceProvider : KotlinCoroutinesAsyncStackTraceP
|
||||
private companion object {
|
||||
const val DEBUG_METADATA_KT = "kotlin.coroutines.jvm.internal.DebugMetadataKt"
|
||||
|
||||
private val LOG = Logger.getInstance(this::class.java)
|
||||
|
||||
tailrec fun findBaseContinuationSuperSupertype(type: ClassType): ClassType? {
|
||||
if (type.name() == "kotlin.coroutines.jvm.internal.BaseContinuationImpl") {
|
||||
return type
|
||||
@@ -37,25 +35,7 @@ class KotlinCoroutinesAsyncStackTraceProvider : KotlinCoroutinesAsyncStackTraceP
|
||||
}
|
||||
|
||||
override fun getAsyncStackTrace(stackFrame: JavaStackFrame, suspendContext: SuspendContextImpl): List<StackFrameItem>? {
|
||||
return try {
|
||||
getAsyncStackTraceSafe(stackFrame.stackFrameProxy, suspendContext)
|
||||
} catch (e: Exception) {
|
||||
handleException(e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleException(e: Exception) {
|
||||
when (if (e is EvaluateException) e.cause ?: e else e) {
|
||||
is ObjectCollectedException, is IncompatibleThreadStateException, is VMDisconnectedException -> {}
|
||||
else -> {
|
||||
if (e is EvaluateException) {
|
||||
LOG.debug("Cannot evaluate async stack trace", e)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
return hopelessAware { getAsyncStackTraceSafe(stackFrame.stackFrameProxy, suspendContext) }
|
||||
}
|
||||
|
||||
fun getAsyncStackTraceSafe(frameProxy: StackFrameProxyImpl, suspendContext: SuspendContextImpl): List<StackFrameItem>? {
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ class KotlinPositionManager(private val myDebugProcess: DebugProcess) : MultiReq
|
||||
val psiFile = sourcePosition.file
|
||||
if (psiFile is KtFile) {
|
||||
if (!ProjectRootsUtil.isInProjectOrLibSource(psiFile)) return emptyList()
|
||||
return DebuggerClassNameProvider(myDebugProcess).getClassesForPosition(sourcePosition)
|
||||
return hopelessAware { DebuggerClassNameProvider(myDebugProcess).getClassesForPosition(sourcePosition) } ?: emptyList()
|
||||
}
|
||||
|
||||
if (psiFile is ClsFileImpl) {
|
||||
|
||||
+7
-4
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.core.util.getKotlinJvmRuntimeMarkerClass
|
||||
import org.jetbrains.kotlin.idea.debugger.evaluate.compilation.DebugLabelPropertyDescriptorProvider
|
||||
import org.jetbrains.kotlin.idea.debugger.getContextElement
|
||||
import org.jetbrains.kotlin.idea.debugger.hopelessAware
|
||||
import org.jetbrains.kotlin.idea.j2k.J2kPostProcessor
|
||||
import org.jetbrains.kotlin.idea.j2k.convertToKotlin
|
||||
import org.jetbrains.kotlin.idea.j2k.j2kText
|
||||
@@ -175,10 +176,12 @@ class KotlinCodeFragmentFactory : CodeFragmentFactory() {
|
||||
val worker = object : DebuggerCommandImpl() {
|
||||
override fun action() {
|
||||
try {
|
||||
val frame = if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
contextElement?.getCopyableUserData(DEBUG_CONTEXT_FOR_TESTS)?.frameProxy?.stackFrame
|
||||
} else {
|
||||
debuggerContext.frameProxy?.stackFrame
|
||||
val frame = hopelessAware {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
contextElement?.getCopyableUserData(DEBUG_CONTEXT_FOR_TESTS)?.frameProxy?.stackFrame
|
||||
} else {
|
||||
debuggerContext.frameProxy?.stackFrame
|
||||
}
|
||||
}
|
||||
|
||||
frameInfo = FrameInfo.from(debuggerContext.project, frame)
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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
|
||||
|
||||
import com.intellij.debugger.engine.evaluation.EvaluateException
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.sun.jdi.IncompatibleThreadStateException
|
||||
import com.sun.jdi.VMDisconnectedException
|
||||
|
||||
private val LOG = Logger.getInstance("HopelessExceptionUtils")
|
||||
|
||||
inline fun <T : Any> hopelessAware(block: () -> T?): T? {
|
||||
return try {
|
||||
block()
|
||||
} catch (e: Exception) {
|
||||
handleHopelessException(e)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun handleHopelessException(e: Exception) {
|
||||
when (if (e is EvaluateException) e.cause ?: e else e) {
|
||||
is IncompatibleThreadStateException, is VMDisconnectedException -> {}
|
||||
else -> {
|
||||
if (e is EvaluateException) {
|
||||
LOG.debug("Cannot evaluate async stack trace", e)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user