use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project android by JetBrains.
the class BitmapEvaluatorProvider method downsizeBitmap.
@Override
public boolean downsizeBitmap(@NotNull Dimension currentDimensions) throws EvaluateException {
DebugProcessImpl debugProcess = myEvaluationContext.getDebugProcess();
Method createScaledBitmapMethod = DebuggerUtils.findMethod(myBitmap.referenceType(), "createScaledBitmap", "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;");
if (createScaledBitmapMethod == null) {
return false;
}
double s = Math.max(currentDimensions.getHeight(), currentDimensions.getWidth()) / MAX_DIMENSION;
VirtualMachineProxyImpl vm = myEvaluationContext.getDebugProcess().getVirtualMachineProxy();
Value dstWidth = DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getWidth() / s));
Value dstHeight = DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getHeight() / s));
Value filter = DebuggerUtilsEx.createValue(vm, "boolean", Boolean.FALSE);
Value result = debugProcess.invokeMethod(myEvaluationContext, myBitmap, createScaledBitmapMethod, Arrays.asList(myBitmap, dstWidth, dstHeight, filter));
if (result != null) {
myBitmap = (ObjectReference) result;
}
return result != null;
}
use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project kotlin by JetBrains.
the class CompilingEvaluatorUtils method defineClass.
public static void defineClass(@NotNull String className, byte[] bytecodes, @NotNull EvaluationContext context, @NotNull DebugProcess process, @NotNull ClassLoaderReference classLoader) throws ClassNotLoadedException, EvaluateException, InvalidTypeException {
VirtualMachineProxyImpl proxy = (VirtualMachineProxyImpl) process.getVirtualMachineProxy();
Method defineMethod = ((ClassType) classLoader.referenceType()).concreteMethodByName("defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;");
byte[] bytes = changeSuperToMagicAccessor(bytecodes);
ArrayList<Value> args = new ArrayList<Value>();
StringReference name = proxy.mirrorOf(className);
keep(name, context);
args.add(name);
args.add(mirrorOf(bytes, context, process));
args.add(proxy.mirrorOf(0));
args.add(proxy.mirrorOf(bytes.length));
process.invokeMethod(context, classLoader, defineMethod, args);
}
use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project android by JetBrains.
the class BitmapEvaluatorProvider method copyToBuffer.
@Nullable
private List<Value> copyToBuffer(@NotNull Dimension size) throws EvaluateException {
DebugProcessImpl debugProcess = myEvaluationContext.getDebugProcess();
VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy();
List<ReferenceType> classes = virtualMachineProxy.classesByName("byte[]");
if (classes.size() != 1 || !(classes.get(0) instanceof ArrayType)) {
return null;
}
ArrayType byteArrayType = (ArrayType) classes.get(0);
classes = virtualMachineProxy.classesByName("java.nio.ByteBuffer");
if (classes.size() != 1 || !(classes.get(0) instanceof ClassType)) {
return null;
}
ClassType byteBufferType = (ClassType) classes.get(0);
Method wrapMethod = DebuggerUtils.findMethod(byteBufferType, "wrap", "([B)Ljava/nio/ByteBuffer;");
if (wrapMethod == null) {
return null;
}
ArrayReference byteArray = byteArrayType.newInstance(size.width * size.height * 4);
Value byteBufferRef = debugProcess.invokeMethod(myEvaluationContext, byteBufferType, wrapMethod, ImmutableList.of(byteArray));
Method copyToBufferMethod = DebuggerUtils.findMethod(myBitmap.referenceType(), "copyPixelsToBuffer", "(Ljava/nio/Buffer;)V");
if (copyToBufferMethod == null) {
return null;
}
debugProcess.invokeMethod(myEvaluationContext, myBitmap, copyToBufferMethod, ImmutableList.of(byteBufferRef));
return byteArray.getValues();
}
use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project android by JetBrains.
the class DynamicResourceIdResolver method getAndroidResourceName.
@Nullable
@Override
public String getAndroidResourceName(int resId) {
String id = myDelegate.getAndroidResourceName(resId);
if (id != null) {
return id;
}
DebugProcess debugProcess = myContext.getDebugProcess();
VirtualMachineProxyImpl vmProxy = (VirtualMachineProxyImpl) debugProcess.getVirtualMachineProxy();
List<ReferenceType> classes = vmProxy.classesByName(CLASS_RESOURCES);
if (classes.isEmpty()) {
LOG.warn(CLASS_RESOURCES + " class not loaded?");
return null;
}
if (classes.size() != 1) {
LOG.warn("Expected a single Resource class loaded, but found " + classes.size());
}
ReferenceType resourcesClassType = classes.get(0);
Method getResourceNameMethod = DebuggerUtils.findMethod(resourcesClassType, "getResourceName", "(I)Ljava/lang/String;");
if (getResourceNameMethod == null) {
LOG.warn("Unable to locate getResourceName(int id) in class " + resourcesClassType.name());
return null;
}
List<ObjectReference> instances = resourcesClassType.instances(10);
if (instances.isEmpty()) {
LOG.warn("No instances of Resource class found");
return null;
}
List args = Collections.singletonList(DebuggerUtilsEx.createValue(vmProxy, "int", resId));
for (ObjectReference ref : instances) {
try {
Value value = debugProcess.invokeMethod(myContext, ref, getResourceNameMethod, args);
if (value instanceof StringReference) {
StringReference nameRef = (StringReference) value;
return nameRef.value();
}
} catch (EvaluateException e) {
ObjectReference exception = e.getExceptionFromTargetVM();
// do not log Resources$NotFoundException
if (exception == null || !DebuggerUtils.instanceOf(exception.type(), "android.content.res.Resources$NotFoundException")) {
LOG.warn("Unexpected error while invoking Resources.getResourceName()", e);
// continue and try this on other object references
}
}
}
return null;
}
use of com.intellij.debugger.jdi.VirtualMachineProxyImpl in project intellij-community by JetBrains.
the class DebugProcessImpl method getVirtualMachineProxy.
@NotNull
@Override
public VirtualMachineProxyImpl getVirtualMachineProxy() {
DebuggerManagerThreadImpl.assertIsManagerThread();
final VirtualMachineProxyImpl vm = myVirtualMachineProxy;
if (vm == null) {
throw new VMDisconnectedException();
}
return vm;
}
Aggregations