From c623afe79d15453ce3075d73126433de54b5f2bf Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Thu, 17 Oct 2024 15:00:10 +0200 Subject: [PATCH] [debugger] reduce usage of obsolete DebugProcess.getVirtualMachineProxy GitOrigin-RevId: 3a405f6344b45a3f2ff8182e4576caa35617c7e2 --- .../idea/debugger/base/util/DexDebugFacility.kt | 3 ++- .../idea/debugger/core/KotlinPositionManager.kt | 6 +++--- .../core/breakpoints/KotlinFieldBreakpoint.kt | 5 ++--- .../kotlin/idea/debugger/core/debuggerUtil.kt | 14 +++++--------- .../smartStepInto/KotlinLambdaAsyncMethodFilter.kt | 4 ++-- .../debugger/evaluate/KotlinEvaluatorBuilder.kt | 2 +- .../classLoading/AndroidOClassLoadingAdapter.kt | 2 +- .../classLoading/OrdinaryClassLoadingAdapter.kt | 3 ++- 8 files changed, 18 insertions(+), 21 deletions(-) diff --git a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/DexDebugFacility.kt b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/DexDebugFacility.kt index f31e51d9a469..5a78d01657fc 100644 --- a/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/DexDebugFacility.kt +++ b/plugins/kotlin/jvm-debugger/base/util/src/org/jetbrains/kotlin/idea/debugger/base/util/DexDebugFacility.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.kotlin.idea.debugger.base.util @@ -11,6 +11,7 @@ object DexDebugFacility { return virtualMachine.name() == "Dalvik" } + @Deprecated("Use isDex(virtualMachine)") fun isDex(debugProcess: DebugProcess): Boolean { val virtualMachineProxy = debugProcess.virtualMachineProxy as? VirtualMachineProxyImpl ?: return false return isDex(virtualMachineProxy.virtualMachine) diff --git a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/KotlinPositionManager.kt b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/KotlinPositionManager.kt index a106131c092b..7633a191a1be 100644 --- a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/KotlinPositionManager.kt +++ b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/KotlinPositionManager.kt @@ -377,7 +377,7 @@ class KotlinPositionManager(private val debugProcess: DebugProcess) : MultiReque getInlineArgumentSymbol(expression)?.isCrossinline } if (isCrossinline != null && (!isCrossinline || isInlinedArgument(expression, location))) { - if (isInsideInlineArgument(expression, location, debugProcess as DebugProcessImpl)) { + if (isInsideInlineArgument(expression, location)) { innermostInlinedElement = expression } } else { @@ -637,8 +637,8 @@ class KotlinPositionManager(private val debugProcess: DebugProcess) : MultiReque throw NoDataException.INSTANCE } try { - if (DexDebugFacility.isDex(debugProcess) && - (debugProcess.virtualMachineProxy as? VirtualMachineProxyImpl)?.canGetSourceDebugExtension() != true) { + val virtualMachine = type.virtualMachine() + if (DexDebugFacility.isDex(virtualMachine) && !virtualMachine.canGetSourceDebugExtension()) { // If we cannot get source debug extension information, we approximate information for inline functions. // This allows us to stop on some breakpoints in inline functions, but does not work very well. // Source debug extensions are not available on Android devices before Android O. diff --git a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/breakpoints/KotlinFieldBreakpoint.kt b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/breakpoints/KotlinFieldBreakpoint.kt index 62bf3493fc26..c567fdc0f3bc 100644 --- a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/breakpoints/KotlinFieldBreakpoint.kt +++ b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/breakpoints/KotlinFieldBreakpoint.kt @@ -83,7 +83,6 @@ class KotlinFieldBreakpoint( breakpointType = evaluationElement?.let(::computeBreakpointType) ?: return - val vm = debugProcess.virtualMachineProxy try { if (properties.watchInitialization) { val sourcePosition = sourcePosition @@ -106,14 +105,14 @@ class KotlinFieldBreakpoint( val field = DebuggerUtils.findField(refType, getFieldName()) if (field != null) { val manager = debugProcess.requestsManager - if (properties.watchModification && vm.canWatchFieldModification()) { + if (properties.watchModification && refType.virtualMachine().canWatchFieldModification()) { val request = manager.createModificationWatchpointRequest(this, field) debugProcess.requestsManager.enableRequest(request) if (LOG.isDebugEnabled) { LOG.debug("Modification request added") } } - if (properties.watchAccess && vm.canWatchFieldAccess()) { + if (properties.watchAccess && refType.virtualMachine().canWatchFieldAccess()) { val request = manager.createAccessWatchpointRequest(this, field) debugProcess.requestsManager.enableRequest(request) if (LOG.isDebugEnabled) { diff --git a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/debuggerUtil.kt b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/debuggerUtil.kt index 453f12e17c87..c5f3f4c5f8af 100644 --- a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/debuggerUtil.kt +++ b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/core/debuggerUtil.kt @@ -28,11 +28,7 @@ import org.jetbrains.kotlin.idea.debugger.base.util.KotlinDebuggerConstants.INVO import org.jetbrains.kotlin.idea.debugger.base.util.KotlinDebuggerConstants.KOTLIN_STRATA_NAME import org.jetbrains.kotlin.idea.debugger.core.DebuggerUtils.getBorders import org.jetbrains.kotlin.load.java.JvmAbi -import org.jetbrains.kotlin.psi.KtCallableReferenceExpression -import org.jetbrains.kotlin.psi.KtElement -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi.KtFunction +import org.jetbrains.kotlin.psi.* import org.jetbrains.org.objectweb.asm.Label import org.jetbrains.org.objectweb.asm.MethodVisitor import org.jetbrains.org.objectweb.asm.Opcodes @@ -73,8 +69,8 @@ fun ReferenceType.containsKotlinStrata() = availableStrata().contains(KOTLIN_STR fun ReferenceType.containsKotlinStrataAsync(): CompletableFuture = DebuggerUtilsAsync.availableStrata(this).thenApply { it.contains(KOTLIN_STRATA_NAME) } -internal suspend fun isInsideInlineArgument(inlineArgument: KtExpression, location: Location, debugProcess: DebugProcessImpl): Boolean = - isInlinedArgument(location.visibleVariables(debugProcess), inlineArgument) +internal suspend fun isInsideInlineArgument(inlineArgument: KtExpression, location: Location): Boolean = + isInlinedArgument(location.visibleVariables(location.virtualMachine()), inlineArgument) /** * Check whether [inlineArgument] is a lambda that is inlined in bytecode @@ -144,8 +140,8 @@ private fun functionNameByArgument(argument: KtExpression): String? = function.name.asString() } -private fun Location.visibleVariables(debugProcess: DebugProcessImpl): List { - val stackFrame = MockStackFrame(this, debugProcess.virtualMachineProxy.virtualMachine) +private fun Location.visibleVariables(virtualMachine: VirtualMachine): List { + val stackFrame = MockStackFrame(this, virtualMachine) return stackFrame.visibleVariables() } diff --git a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinLambdaAsyncMethodFilter.kt b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinLambdaAsyncMethodFilter.kt index 8777f12d510b..cee91dc7e783 100644 --- a/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinLambdaAsyncMethodFilter.kt +++ b/plugins/kotlin/jvm-debugger/core/src/org/jetbrains/kotlin/idea/debugger/stepping/smartStepInto/KotlinLambdaAsyncMethodFilter.kt @@ -194,7 +194,7 @@ class KotlinLambdaAsyncMethodFilter( if (isAsyncSuspendLambda) return name == CREATE return lambdaFilter.isTargetLambdaName(name) } - + private fun ObjectReference.checkLambdaBreakpoint(context: EvaluationContextImpl, location: Location): Boolean { val thread = context.suspendContext.thread ?: return false val methodName = location.safeMethod()?.name() ?: return false @@ -205,7 +205,7 @@ class KotlinLambdaAsyncMethodFilter( val frameIndex = if (methodName.isGeneratedIrBackendLambdaMethodName()) 1 else 0 return isTargetLambda(thread, frameIndex) // On ART SAM converted lambdas get an additional stack frame from r8 in their stack trace - || DexDebugFacility.isDex(context.debugProcess) && isTargetLambda(thread, 2) + || DexDebugFacility.isDex(event.virtualMachine()) && isTargetLambda(thread, 2) // For lambdas passed to Java functions, the lambda could be additionally wrapped for type compatibility. // One of the previous frames (heuristically 3rd frame) should contain the original lambda. || isTargetLambda(thread, 3) 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 4c2100f8dba3..642f85eccb18 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 @@ -77,7 +77,7 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, private val sourcePositi override fun evaluate(context: EvaluationContextImpl): Any? { if (codeFragment.text.isEmpty()) { - return context.debugProcess.virtualMachineProxy.mirrorOfVoid() + return context.suspendContext.virtualMachineProxy.mirrorOfVoid() } if (!context.debugProcess.isAttached) { diff --git a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/AndroidOClassLoadingAdapter.kt b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/AndroidOClassLoadingAdapter.kt index 36f5f5bc85d4..fe6cd4e1f5da 100644 --- a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/AndroidOClassLoadingAdapter.kt +++ b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/AndroidOClassLoadingAdapter.kt @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.idea.debugger.base.util.evaluate.ExecutionContext class AndroidOClassLoadingAdapter : AbstractAndroidClassLoadingAdapter() { override fun isApplicable(context: ExecutionContext, info: ClassLoadingAdapter.Companion.ClassInfoForEvaluator) = with(info) { - isCompilingEvaluatorPreferred && DexDebugFacility.isDex(context.debugProcess) + isCompilingEvaluatorPreferred && DexDebugFacility.isDex(context.evaluationContext.virtualMachineProxy.virtualMachine) } private fun resolveClassLoaderClass(context: ExecutionContext): ClassType? { diff --git a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/OrdinaryClassLoadingAdapter.kt b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/OrdinaryClassLoadingAdapter.kt index 9070f807eb8f..a09618cfd633 100644 --- a/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/OrdinaryClassLoadingAdapter.kt +++ b/plugins/kotlin/jvm-debugger/evaluation/src/org/jetbrains/kotlin/idea/debugger/evaluate/classLoading/OrdinaryClassLoadingAdapter.kt @@ -86,7 +86,8 @@ class OrdinaryClassLoadingAdapter : ClassLoadingAdapter { } override fun isApplicable(context: ExecutionContext, info: ClassLoadingAdapter.Companion.ClassInfoForEvaluator): Boolean { - return info.isCompilingEvaluatorPreferred && context.classLoader != null && !DexDebugFacility.isDex(context.debugProcess) + return info.isCompilingEvaluatorPreferred && context.classLoader != null + && !DexDebugFacility.isDex(context.evaluationContext.virtualMachineProxy.virtualMachine) } override fun loadClasses(context: ExecutionContext, classes: Collection): ClassLoaderReference {