Minor. remove import package usage from jdiEval.kt, jdiValues.kt and jdiTest.kt
This commit is contained in:
@@ -16,20 +16,23 @@
|
||||
|
||||
package org.jetbrains.eval4j.jdi
|
||||
|
||||
import com.sun.jdi
|
||||
import com.sun.jdi.*
|
||||
import com.sun.jdi.Value as jdi_Value
|
||||
import com.sun.jdi.Type as jdi_Type
|
||||
import com.sun.jdi.ClassNotLoadedException
|
||||
import com.sun.jdi.Method
|
||||
import com.sun.jdi.ObjectReference
|
||||
import org.jetbrains.eval4j.*
|
||||
import org.jetbrains.eval4j.Value
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
val CLASS = Type.getType(javaClass<Class<*>>())
|
||||
val BOOTSTRAP_CLASS_DESCRIPTORS = setOf("Ljava/lang/String;", "Ljava/lang/ClassLoader;", "Ljava/lang/Class;")
|
||||
|
||||
public class JDIEval(
|
||||
private val vm: jdi.VirtualMachine,
|
||||
private val classLoader: jdi.ClassLoaderReference?,
|
||||
private val thread: jdi.ThreadReference,
|
||||
private val vm: VirtualMachine,
|
||||
private val classLoader: ClassLoaderReference?,
|
||||
private val thread: ThreadReference,
|
||||
private val invokePolicy: Int
|
||||
) : Eval {
|
||||
|
||||
@@ -103,8 +106,8 @@ public class JDIEval(
|
||||
listOf(value)).boolean
|
||||
}
|
||||
|
||||
fun Type.asReferenceType(): jdi.ReferenceType = loadClass(this).jdiClass!!.reflectedType()
|
||||
fun Type.asArrayType(): jdi.ArrayType = asReferenceType() as jdi.ArrayType
|
||||
fun Type.asReferenceType(): ReferenceType = loadClass(this).jdiClass!!.reflectedType()
|
||||
fun Type.asArrayType(): ArrayType = asReferenceType() as ArrayType
|
||||
|
||||
override fun newArray(arrayType: Type, size: Int): Value {
|
||||
val jdiArrayType = arrayType.asArrayType()
|
||||
@@ -134,7 +137,7 @@ public class JDIEval(
|
||||
return fillArray(arrayType.arrayElementType, dimensionSizes[0], dimensionSizes.drop(1))
|
||||
}
|
||||
|
||||
private fun Value.array() = jdiObj.checkNull() as jdi.ArrayReference
|
||||
private fun Value.array() = jdiObj.checkNull() as ArrayReference
|
||||
|
||||
override fun getArrayLength(array: Value): Value {
|
||||
return int(array.array().length())
|
||||
@@ -158,7 +161,7 @@ public class JDIEval(
|
||||
}
|
||||
}
|
||||
|
||||
private fun findField(fieldDesc: FieldDescription): jdi.Field {
|
||||
private fun findField(fieldDesc: FieldDescription): Field {
|
||||
val _class = fieldDesc.ownerType.asReferenceType()
|
||||
val field = _class.fieldByName(fieldDesc.name)
|
||||
if (field == null) {
|
||||
@@ -167,7 +170,7 @@ public class JDIEval(
|
||||
return field
|
||||
}
|
||||
|
||||
private fun findStaticField(fieldDesc: FieldDescription): jdi.Field {
|
||||
private fun findStaticField(fieldDesc: FieldDescription): Field {
|
||||
val field = findField(fieldDesc)
|
||||
if (!field.isStatic()) {
|
||||
throwBrokenCodeException(NoSuchFieldError("Field is not static: $fieldDesc"))
|
||||
@@ -188,7 +191,7 @@ public class JDIEval(
|
||||
}
|
||||
|
||||
val _class = field.declaringType()
|
||||
if (_class !is jdi.ClassType) {
|
||||
if (_class !is ClassType) {
|
||||
throwBrokenCodeException(NoSuchFieldError("Can't a field in a non-class: $field"))
|
||||
}
|
||||
|
||||
@@ -196,9 +199,9 @@ public class JDIEval(
|
||||
mayThrow { _class.setValue(field, jdiValue) }
|
||||
}
|
||||
|
||||
private fun findMethod(methodDesc: MethodDescription, _class: jdi.ReferenceType = methodDesc.ownerType.asReferenceType()): jdi.Method {
|
||||
private fun findMethod(methodDesc: MethodDescription, _class: ReferenceType = methodDesc.ownerType.asReferenceType()): Method {
|
||||
val method = when (_class) {
|
||||
is jdi.ClassType -> {
|
||||
is ClassType -> {
|
||||
val m = _class.concreteMethodByName(methodDesc.name, methodDesc.desc)
|
||||
if (m == null) listOf() else listOf(m)
|
||||
}
|
||||
@@ -216,7 +219,7 @@ public class JDIEval(
|
||||
throwBrokenCodeException(NoSuchMethodError("Method is not static: $methodDesc"))
|
||||
}
|
||||
val _class = method.declaringType()
|
||||
if (_class !is jdi.ClassType) throwBrokenCodeException(NoSuchMethodError("Static method is a non-class type: $method"))
|
||||
if (_class !is ClassType) throwBrokenCodeException(NoSuchMethodError("Static method is a non-class type: $method"))
|
||||
|
||||
val args = mapArguments(arguments, method.safeArgumentTypes())
|
||||
args.disableCollection()
|
||||
@@ -274,7 +277,7 @@ public class JDIEval(
|
||||
if (invokespecial && methodDesc.name == "<init>") {
|
||||
// Constructor call
|
||||
val ctor = findMethod(methodDesc)
|
||||
val _class = (instance as NewObjectValue).asmType.asReferenceType() as jdi.ClassType
|
||||
val _class = (instance as NewObjectValue).asmType.asReferenceType() as ClassType
|
||||
val args = mapArguments(arguments, ctor.safeArgumentTypes())
|
||||
args.disableCollection()
|
||||
val result = mayThrow { _class.newInstance(thread, ctor, args, invokePolicy) }
|
||||
@@ -302,23 +305,23 @@ public class JDIEval(
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<jdi.Value?>.disableCollection() {
|
||||
private fun List<jdi_Value?>.disableCollection() {
|
||||
forEach { (it as? ObjectReference)?.disableCollection() }
|
||||
}
|
||||
|
||||
private fun List<jdi.Value?>.enableCollection() {
|
||||
private fun List<jdi_Value?>.enableCollection() {
|
||||
forEach { (it as? ObjectReference)?.enableCollection() }
|
||||
}
|
||||
|
||||
|
||||
private fun mapArguments(arguments: List<Value>, expecetedTypes: List<jdi.Type>): List<jdi.Value?> {
|
||||
private fun mapArguments(arguments: List<Value>, expecetedTypes: List<jdi_Type>): List<jdi_Value?> {
|
||||
return arguments.zip(expecetedTypes).map {
|
||||
val (arg, expectedType) = it
|
||||
arg.asJdiValue(vm, expectedType.asType())
|
||||
}
|
||||
}
|
||||
|
||||
private fun jdi.Method.safeArgumentTypes(): List<jdi.Type> {
|
||||
private fun Method.safeArgumentTypes(): List<jdi_Type> {
|
||||
try {
|
||||
return argumentTypes()
|
||||
}
|
||||
@@ -343,7 +346,7 @@ fun <T> mayThrow(f: () -> T): T {
|
||||
try {
|
||||
return f()
|
||||
}
|
||||
catch (e: jdi.InvocationException) {
|
||||
catch (e: InvocationException) {
|
||||
throw ThrownFromEvaluatedCodeException(e.exception().asValue())
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,25 @@
|
||||
|
||||
package org.jetbrains.eval4j.jdi
|
||||
|
||||
import com.sun.jdi
|
||||
import com.sun.jdi.ClassObjectReference
|
||||
import com.sun.jdi.VirtualMachine
|
||||
import org.jetbrains.eval4j.*
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.ACC_STATIC
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
||||
import com.sun.jdi.BooleanValue as jdi_BooleanValue
|
||||
import com.sun.jdi.ByteValue as jdi_ByteValue
|
||||
import com.sun.jdi.CharValue as jdi_CharValue
|
||||
import com.sun.jdi.DoubleValue as jdi_DoubleValue
|
||||
import com.sun.jdi.FloatValue as jdi_FloatValue
|
||||
import com.sun.jdi.IntegerValue as jdi_IntegerValue
|
||||
import com.sun.jdi.LongValue as jdi_LongValue
|
||||
import com.sun.jdi.ObjectReference as jdi_ObjectReference
|
||||
import com.sun.jdi.ShortValue as jdi_ShortValue
|
||||
import com.sun.jdi.Type as jdi_Type
|
||||
import com.sun.jdi.Value as jdi_Value
|
||||
import com.sun.jdi.VoidValue as jdi_VoidValue
|
||||
|
||||
public fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Frame<Value> {
|
||||
val isStatic = (methodNode.access and ACC_STATIC) != 0
|
||||
@@ -51,39 +64,39 @@ public fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Fra
|
||||
|
||||
class JDIFailureException(message: String?, cause: Throwable? = null): RuntimeException(message, cause)
|
||||
|
||||
public fun jdi.ObjectReference?.asValue(): ObjectValue {
|
||||
public fun jdi_ObjectReference?.asValue(): ObjectValue {
|
||||
return when (this) {
|
||||
null -> NULL_VALUE
|
||||
else -> ObjectValue(this, type().asType())
|
||||
}
|
||||
}
|
||||
|
||||
public fun jdi.Value?.asValue(): Value {
|
||||
public fun jdi_Value?.asValue(): Value {
|
||||
return when (this) {
|
||||
null -> NULL_VALUE
|
||||
is jdi.VoidValue -> VOID_VALUE
|
||||
is jdi.BooleanValue -> IntValue(intValue(), Type.BOOLEAN_TYPE)
|
||||
is jdi.ByteValue -> IntValue(intValue(), Type.BYTE_TYPE)
|
||||
is jdi.ShortValue -> IntValue(intValue(), Type.SHORT_TYPE)
|
||||
is jdi.CharValue -> IntValue(intValue(), Type.CHAR_TYPE)
|
||||
is jdi.IntegerValue -> IntValue(intValue(), Type.INT_TYPE)
|
||||
is jdi.LongValue -> LongValue(longValue())
|
||||
is jdi.FloatValue -> FloatValue(floatValue())
|
||||
is jdi.DoubleValue -> DoubleValue(doubleValue())
|
||||
is jdi.ObjectReference -> this.asValue()
|
||||
is jdi_VoidValue -> VOID_VALUE
|
||||
is jdi_BooleanValue -> IntValue(intValue(), Type.BOOLEAN_TYPE)
|
||||
is jdi_ByteValue -> IntValue(intValue(), Type.BYTE_TYPE)
|
||||
is jdi_ShortValue -> IntValue(intValue(), Type.SHORT_TYPE)
|
||||
is jdi_CharValue -> IntValue(intValue(), Type.CHAR_TYPE)
|
||||
is jdi_IntegerValue -> IntValue(intValue(), Type.INT_TYPE)
|
||||
is jdi_LongValue -> LongValue(longValue())
|
||||
is jdi_FloatValue -> FloatValue(floatValue())
|
||||
is jdi_DoubleValue -> DoubleValue(doubleValue())
|
||||
is jdi_ObjectReference -> this.asValue()
|
||||
else -> throw JDIFailureException("Unknown value: $this")
|
||||
}
|
||||
}
|
||||
|
||||
fun jdi.Type.asType(): Type = Type.getType(this.signature())
|
||||
fun jdi_Type.asType(): Type = Type.getType(this.signature())
|
||||
|
||||
val Value.jdiObj: jdi.ObjectReference?
|
||||
get() = this.obj() as jdi.ObjectReference?
|
||||
val Value.jdiObj: jdi_ObjectReference?
|
||||
get() = this.obj() as jdi_ObjectReference?
|
||||
|
||||
val Value.jdiClass: jdi.ClassObjectReference?
|
||||
get() = this.jdiObj as jdi.ClassObjectReference?
|
||||
val Value.jdiClass: ClassObjectReference?
|
||||
get() = this.jdiObj as ClassObjectReference?
|
||||
|
||||
public fun Value.asJdiValue(vm: jdi.VirtualMachine, expectedType: Type): jdi.Value? {
|
||||
public fun Value.asJdiValue(vm: VirtualMachine, expectedType: Type): jdi_Value? {
|
||||
return when (this) {
|
||||
NULL_VALUE -> null
|
||||
VOID_VALUE -> vm.mirrorOfVoid()
|
||||
@@ -98,8 +111,8 @@ public fun Value.asJdiValue(vm: jdi.VirtualMachine, expectedType: Type): jdi.Val
|
||||
is LongValue -> vm.mirrorOf(value)
|
||||
is FloatValue -> vm.mirrorOf(value)
|
||||
is DoubleValue -> vm.mirrorOf(value)
|
||||
is ObjectValue -> value as jdi.ObjectReference
|
||||
is NewObjectValue -> this.obj() as jdi.ObjectReference
|
||||
is ObjectValue -> value as jdi_ObjectReference
|
||||
is NewObjectValue -> this.obj() as jdi_ObjectReference
|
||||
else -> throw JDIFailureException("Unknown value: $this")
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.eval4j.jdi.test
|
||||
|
||||
import org.jetbrains.eval4j.*
|
||||
import com.sun.jdi
|
||||
import com.sun.jdi.*
|
||||
import junit.framework.TestSuite
|
||||
import org.jetbrains.eval4j.test.buildTestSuite
|
||||
import junit.framework.TestCase
|
||||
@@ -30,11 +30,13 @@ import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.eval4j.test.getTestName
|
||||
import com.sun.jdi.ObjectReference
|
||||
import com.sun.jdi.event.BreakpointEvent
|
||||
import com.sun.jdi.event.ClassPrepareEvent
|
||||
|
||||
val DEBUGEE_CLASS = javaClass<Debugee>()
|
||||
|
||||
fun suite(): TestSuite {
|
||||
val connectors = jdi.Bootstrap.virtualMachineManager().launchingConnectors()
|
||||
val connectors = Bootstrap.virtualMachineManager().launchingConnectors()
|
||||
val connector = connectors[0]
|
||||
println("Using connector $connector")
|
||||
|
||||
@@ -54,8 +56,8 @@ fun suite(): TestSuite {
|
||||
req.enable()
|
||||
|
||||
val latch = CountDownLatch(1)
|
||||
var classLoader : jdi.ClassLoaderReference? = null
|
||||
var thread : jdi.ThreadReference? = null
|
||||
var classLoader : ClassLoaderReference? = null
|
||||
var thread : ThreadReference? = null
|
||||
|
||||
Thread {
|
||||
val eventQueue = vm.eventQueue()
|
||||
@@ -63,7 +65,7 @@ fun suite(): TestSuite {
|
||||
val eventSet = eventQueue.remove()
|
||||
for (event in eventSet.eventIterator()) {
|
||||
when (event) {
|
||||
is jdi.event.ClassPrepareEvent -> {
|
||||
is ClassPrepareEvent -> {
|
||||
val _class = event.referenceType()!!
|
||||
if (_class.name() == debugeeName) {
|
||||
for (l in _class.allLineLocations()) {
|
||||
@@ -78,7 +80,7 @@ fun suite(): TestSuite {
|
||||
}
|
||||
}
|
||||
}
|
||||
is jdi.event.BreakpointEvent -> {
|
||||
is BreakpointEvent -> {
|
||||
println("Suspended at: " + event.location())
|
||||
|
||||
thread = event.thread()
|
||||
@@ -122,7 +124,7 @@ fun suite(): TestSuite {
|
||||
eval
|
||||
)
|
||||
|
||||
fun jdi.ObjectReference?.callToString(): String? {
|
||||
fun ObjectReference?.callToString(): String? {
|
||||
if (this == null) return "null"
|
||||
return (eval.invokeMethod(
|
||||
this.asValue(),
|
||||
@@ -132,7 +134,7 @@ fun suite(): TestSuite {
|
||||
"()Ljava/lang/String;",
|
||||
false
|
||||
),
|
||||
listOf()).jdiObj as jdi.StringReference).value()
|
||||
listOf()).jdiObj as StringReference).value()
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user