Evaluate: Pass a constructor with loaded classes to 'runEval4J()'
So even if 'evaluateWithCompilation()' fails, 'runEval4J()' can use the additional classes.
This commit is contained in:
+14
-5
@@ -150,15 +150,15 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
val classLoaderRef = loadClassesSafely(context, compiledData.classes)
|
val classLoaderRef = loadClassesSafely(context, compiledData.classes)
|
||||||
|
|
||||||
val result = if (classLoaderRef != null) {
|
val result = if (classLoaderRef != null) {
|
||||||
evaluateWithCompilation(context, compiledData, classLoaderRef) ?: runEval4j(context, compiledData)
|
evaluateWithCompilation(context, compiledData, classLoaderRef) ?: runEval4j(context, compiledData, classLoaderRef)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
runEval4j(context, compiledData)
|
runEval4j(context, compiledData, classLoaderRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If bytecode was taken from cache and exception was thrown - recompile bytecode and run eval4j again
|
// If bytecode was taken from cache and exception was thrown - recompile bytecode and run eval4j again
|
||||||
if (isCompiledDataFromCache && result is ExceptionThrown && result.kind == ExceptionThrown.ExceptionKind.BROKEN_CODE) {
|
if (isCompiledDataFromCache && result is ExceptionThrown && result.kind == ExceptionThrown.ExceptionKind.BROKEN_CODE) {
|
||||||
return runEval4j(context, extractAndCompile(codeFragment, sourcePosition, context)).toJdiValue(context)
|
return runEval4j(context, extractAndCompile(codeFragment, sourcePosition, context), classLoaderRef).toJdiValue(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (result is InterpreterResult) {
|
return if (result is InterpreterResult) {
|
||||||
@@ -283,6 +283,11 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
val mainClassValue = (eval.loadClass(Type.getObjectType(mainClassAsmNode.name), classLoader) as? ObjectValue)
|
val mainClassValue = (eval.loadClass(Type.getObjectType(mainClassAsmNode.name), classLoader) as? ObjectValue)
|
||||||
val mainClass = (mainClassValue?.value as? ClassObjectReference)?.reflectedType() as? ClassType ?: return null
|
val mainClass = (mainClassValue?.value as? ClassObjectReference)?.reflectedType() as? ClassType ?: return null
|
||||||
|
|
||||||
|
// Preload all classes
|
||||||
|
compiledData.classes.asSequence()
|
||||||
|
.filter { !it.isMainClass() }
|
||||||
|
.forEach { eval.loadClass(Type.getObjectType(it.className), classLoader) }
|
||||||
|
|
||||||
return vm.executeWithBreakpointsDisabled {
|
return vm.executeWithBreakpointsDisabled {
|
||||||
// Prepare the main class
|
// Prepare the main class
|
||||||
|
|
||||||
@@ -304,7 +309,11 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runEval4j(context: EvaluationContextImpl, compiledData: CompiledDataDescriptor): InterpreterResult {
|
private fun runEval4j(
|
||||||
|
context: EvaluationContextImpl,
|
||||||
|
compiledData: CompiledDataDescriptor,
|
||||||
|
classLoader: ClassLoaderReference?
|
||||||
|
): InterpreterResult {
|
||||||
val virtualMachine = context.debugProcess.virtualMachineProxy.virtualMachine
|
val virtualMachine = context.debugProcess.virtualMachineProxy.virtualMachine
|
||||||
var resultValue: InterpreterResult? = null
|
var resultValue: InterpreterResult? = null
|
||||||
|
|
||||||
@@ -321,7 +330,7 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
|
|||||||
override fun visitEnd() {
|
override fun visitEnd() {
|
||||||
virtualMachine.executeWithBreakpointsDisabled {
|
virtualMachine.executeWithBreakpointsDisabled {
|
||||||
val eval = JDIEval(virtualMachine,
|
val eval = JDIEval(virtualMachine,
|
||||||
context.classLoader,
|
classLoader ?: context.classLoader,
|
||||||
context.suspendContext.thread?.threadReference!!,
|
context.suspendContext.thread?.threadReference!!,
|
||||||
context.suspendContext.getInvokePolicy())
|
context.suspendContext.getInvokePolicy())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user