From 29e18c34d7e1b397360c87b7deccd552d6ac2ac8 Mon Sep 17 00:00:00 2001 From: "Alexey.Merkulov" Date: Thu, 26 Dec 2024 18:17:35 +0100 Subject: [PATCH] IDEA-365198 Improve detecting of miscompiled evaluation problems GitOrigin-RevId: 2a68d81ea4e95086a3c37724d28c6c981d194797 --- .../eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt | 9 ++++++++- .../eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt | 6 +++--- .../idea/debugger/evaluate/KotlinEvaluatorBuilder.kt | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt b/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt index ee6fddc6ba9f..30908053b484 100644 --- a/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt +++ b/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/interpreterLoop.kt @@ -50,6 +50,13 @@ abstract class ThrownFromEvalExceptionBase(cause: Throwable) : RuntimeException( override fun toString(): String = "Thrown by evaluator: ${cause}" } +class Eval4JIllegalArgumentException : IllegalArgumentException { + constructor(message: String, cause: Throwable) : super(message, cause) + constructor(message: String) : super(message) +} + +class Eval4JIllegalStateException(message: String, cause: Throwable) : IllegalStateException(message, cause) + class BrokenCode(cause: Throwable) : ThrownFromEvalExceptionBase(cause) // Interpreting exceptions should not be sent to EA @@ -238,7 +245,7 @@ fun interpreterLoop( } private fun Frame.getStackTop(i: Int = 0) = this.getStack(this.stackSize - 1 - i) ?: throwBrokenCodeException( - IllegalArgumentException("Couldn't get value with index = $i from top of stack") + Eval4JIllegalArgumentException("Couldn't get value with index = $i from top of stack") ) // Copied from org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer.analyze() diff --git a/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt b/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt index b8146961f3d0..aa34525c3491 100644 --- a/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt +++ b/plugins/kotlin/jvm-debugger/eval4j/src/org/jetbrains/eval4j/jdi/jdiEval.kt @@ -228,7 +228,7 @@ open class JDIEval( if (internalMethods.isNotEmpty()) { return internalMethods.singleOrNull() - ?: throwBrokenCodeException(IllegalArgumentException("Several internal methods found for $methodDesc")) + ?: throwBrokenCodeException(Eval4JIllegalArgumentException("Several internal methods found for $methodDesc")) } } @@ -515,9 +515,9 @@ private fun JdiOperationResult.ifFail(lazyMessage: () -> String): T { is JdiOperationResult.OK -> this.value is JdiOperationResult.Fail -> { if (cause is IllegalArgumentException) { - throwBrokenCodeException(IllegalArgumentException(lazyMessage(), this.cause)) + throwBrokenCodeException(Eval4JIllegalArgumentException(lazyMessage(), this.cause)) } else { - throwBrokenCodeException(IllegalStateException(lazyMessage(), this.cause)) + throwBrokenCodeException(Eval4JIllegalStateException(lazyMessage(), this.cause)) } } } diff --git a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt index 9668bafb19eb..41216fc77274 100644 --- a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt +++ b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluatorBuilder.kt @@ -163,6 +163,8 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, private val sourcePositi val cause = e.cause val errorType = when { e is ControlFlowException || e is IndexNotReadyException -> StatisticsEvaluationResult.UNRELATED_EXCEPTION + e is LinkageError || e is Eval4JIllegalArgumentException || e is Eval4JIllegalStateException -> + StatisticsEvaluationResult.MISCOMPILED e is Eval4JInterpretingException -> if (!hasCast && e.cause is ClassCastException) StatisticsEvaluationResult.MISCOMPILED else StatisticsEvaluationResult.USER_EXCEPTION