Search in sources :

Example 1 with StackFrameProxy

use of com.intellij.debugger.engine.jdi.StackFrameProxy in project smali by JesusFreke.

the class SmaliCodeFragmentFactory method evaluateRegister.

@Nullable
public static Value evaluateRegister(EvaluationContext context, final SmaliMethod smaliMethod, final int registerNum, final String type) throws EvaluateException {
    if (registerNum >= smaliMethod.getRegisterCount()) {
        return null;
    }
    final StackFrameProxy frameProxy = context.getSuspendContext().getFrameProxy();
    if (frameProxy == null) {
        return null;
    }
    VirtualMachine vm = frameProxy.getStackFrame().virtualMachine();
    Location currentLocation = frameProxy.location();
    if (currentLocation == null) {
        return null;
    }
    Method method = currentLocation.method();
    try {
        final Constructor<LocalVariableImpl> localVariableConstructor = LocalVariableImpl.class.getDeclaredConstructor(VirtualMachine.class, Method.class, Integer.TYPE, Location.class, Location.class, String.class, String.class, String.class);
        localVariableConstructor.setAccessible(true);
        Constructor<LocationImpl> locationConstructor = LocationImpl.class.getDeclaredConstructor(VirtualMachine.class, Method.class, Long.TYPE);
        locationConstructor.setAccessible(true);
        int methodSize = 0;
        for (SmaliInstruction instruction : smaliMethod.getInstructions()) {
            methodSize += instruction.getInstructionSize();
        }
        Location endLocation = null;
        for (int endCodeIndex = (methodSize / 2) - 1; endCodeIndex >= 0; endCodeIndex--) {
            endLocation = method.locationOfCodeIndex(endCodeIndex);
            if (endLocation != null) {
                break;
            }
        }
        if (endLocation == null) {
            return null;
        }
        LocalVariable localVariable = localVariableConstructor.newInstance(vm, method, mapRegister(frameProxy.getStackFrame().virtualMachine(), smaliMethod, registerNum), method.location(), endLocation, String.format("v%d", registerNum), type, null);
        return frameProxy.getStackFrame().getValue(localVariable);
    } catch (NoSuchMethodException e) {
        return null;
    } catch (InstantiationException e) {
        return null;
    } catch (IllegalAccessException e) {
        return null;
    } catch (InvocationTargetException e) {
        return null;
    }
}
Also used : LocalVariableImpl(com.sun.tools.jdi.LocalVariableImpl) StackFrameProxy(com.intellij.debugger.engine.jdi.StackFrameProxy) PsiLocalVariable(com.intellij.psi.PsiLocalVariable) SmaliMethod(org.jf.smalidea.psi.impl.SmaliMethod) SmaliInstruction(org.jf.smalidea.psi.impl.SmaliInstruction) InvocationTargetException(java.lang.reflect.InvocationTargetException) LocationImpl(com.sun.tools.jdi.LocationImpl) Nullable(javax.annotation.Nullable)

Example 2 with StackFrameProxy

use of com.intellij.debugger.engine.jdi.StackFrameProxy in project intellij-community by JetBrains.

the class ContextUtil method getSourcePosition.

@Nullable
public static SourcePosition getSourcePosition(@Nullable final StackFrameContext context) {
    if (context == null) {
        return null;
    }
    DebugProcessImpl debugProcess = (DebugProcessImpl) context.getDebugProcess();
    if (debugProcess == null) {
        return null;
    }
    final StackFrameProxy frameProxy = context.getFrameProxy();
    if (frameProxy == null) {
        return null;
    }
    Location location = null;
    try {
        location = frameProxy.location();
    } catch (Throwable e) {
        LOG.debug(e);
    }
    if (location == null) {
        return null;
    }
    return debugProcess.getPositionManager().getSourcePosition(location);
}
Also used : StackFrameProxy(com.intellij.debugger.engine.jdi.StackFrameProxy) Location(com.sun.jdi.Location) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with StackFrameProxy

use of com.intellij.debugger.engine.jdi.StackFrameProxy in project intellij-community by JetBrains.

the class DescriptorTestCase method localVar.

protected LocalVariableDescriptorImpl localVar(DebuggerTree frameTree, EvaluationContextImpl evaluationContext, String name) {
    try {
        StackFrameProxy frameProxy = evaluationContext.getFrameProxy();
        assert frameProxy != null;
        LocalVariableDescriptorImpl local = frameTree.getNodeFactory().getLocalVariableDescriptor(null, frameProxy.visibleVariableByName(name));
        local.setContext(evaluationContext);
        return local;
    } catch (EvaluateException e) {
        error(e);
        return null;
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) LocalVariableDescriptorImpl(com.intellij.debugger.ui.impl.watch.LocalVariableDescriptorImpl) StackFrameProxy(com.intellij.debugger.engine.jdi.StackFrameProxy)

Aggregations

StackFrameProxy (com.intellij.debugger.engine.jdi.StackFrameProxy)3 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 LocalVariableDescriptorImpl (com.intellij.debugger.ui.impl.watch.LocalVariableDescriptorImpl)1 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)1 Location (com.sun.jdi.Location)1 LocalVariableImpl (com.sun.tools.jdi.LocalVariableImpl)1 LocationImpl (com.sun.tools.jdi.LocationImpl)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Nullable (javax.annotation.Nullable)1 Nullable (org.jetbrains.annotations.Nullable)1 SmaliInstruction (org.jf.smalidea.psi.impl.SmaliInstruction)1 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)1