Search in sources :

Example 11 with VirtualMachineProxyImpl

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;
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl)

Example 12 with VirtualMachineProxyImpl

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);
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) ArrayList(java.util.ArrayList)

Example 13 with VirtualMachineProxyImpl

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();
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with VirtualMachineProxyImpl

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;
}
Also used : DebugProcess(com.intellij.debugger.engine.DebugProcess) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with VirtualMachineProxyImpl

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;
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)21 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)5 DebugProcess (com.intellij.debugger.engine.DebugProcess)4 XDebugSession (com.intellij.xdebugger.XDebugSession)3 Nullable (org.jetbrains.annotations.Nullable)3 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)2 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)2 Project (com.intellij.openapi.project.Project)2 Method (com.sun.jdi.Method)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SourcePosition (com.intellij.debugger.SourcePosition)1 JavaExecutionStack (com.intellij.debugger.engine.JavaExecutionStack)1 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)1 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)1 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)1 MethodReturnValueWatcher (com.intellij.debugger.engine.requests.MethodReturnValueWatcher)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 BreakpointManager (com.intellij.debugger.ui.breakpoints.BreakpointManager)1