com.sun.jdi.LocalVariable Java Examples

The following examples show how to use com.sun.jdi.LocalVariable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectTranslation.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Object createTranslation (Object o, Object v) {
    switch (translationID) {
        case LOCALS_ID:
            if (o instanceof LocalVariable && (v == null || v instanceof Value)) {
                LocalVariable lv = (LocalVariable) o;
                org.netbeans.api.debugger.jpda.LocalVariable local;
                if (v instanceof ObjectReference || v == null) {
                    local = new ObjectLocalVariable (
                        debugger, 
                        (ObjectReference) v, 
                        null, 
                        lv, 
                        JPDADebuggerImpl.getGenericSignature (lv), 
                        null
                    );
                } else {
                    local = new Local (debugger, (PrimitiveValue) v, null, lv, null);
                }
                return local;
            }
        default:
            throw new IllegalStateException(""+o);
    }
}
 
Example #2
Source File: ObjectLocalVariable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private ObjectLocalVariable (
    JPDADebuggerImpl debugger,
    ObjectReference value,
    String className, 
    LocalVariable local, 
    String genericSignature,
    String id,
    CallStackFrameImpl frame
) {
    super (debugger, 
        value, 
        genericSignature, 
        id);
    this.local = local;
    if (frame != null) {
        this.thread = frame.getThread();
        this.depth = frame.getFrameDepth();
    }
    this.className = className;
}
 
Example #3
Source File: Local.java    From netbeans with Apache License 2.0 6 votes vote down vote up
Local (
    JPDADebuggerImpl debugger,
    PrimitiveValue value, 
    String className,
    LocalVariable local,
    CallStackFrameImpl frame
) {
    super (
        debugger, 
        value, 
        getID(local, value)
    );
    this.local = local;
    if (frame != null) {
        this.thread = frame.getThread();
        this.depth = frame.getFrameDepth();
    }
    this.className = className;
}
 
Example #4
Source File: StringObjectFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    ObjectReference foo = this.getObjectReference("Foo");

    assertFalse("Should not accept null type.", formatter.acceptType(null, new HashMap<>()));

    assertFalse("Should not accept Foo type.", formatter.acceptType(foo.referenceType(), new HashMap<>()));

    ObjectReference str = this.getObjectReference("java.lang.String");
    assertTrue("Should accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>()));

    ObjectReference clz = this.getObjectReference("java.lang.Class");
    assertFalse("Should not accept Class type.", formatter.acceptType(clz.referenceType(), new HashMap<>()));

    LocalVariable list = this.getLocalVariable("strList");
    assertFalse("Should not accept List type.", formatter.acceptType(list.type(), new HashMap<>()));

    LocalVariable arrays = this.getLocalVariable("arrays");
    assertFalse("Should not accept array type.", formatter.acceptType(arrays.type(), new HashMap<>()));
}
 
Example #5
Source File: ArrayObjectFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    ObjectReference foo = this.getObjectReference("Foo");

    assertFalse("Should not accept null type.", formatter.acceptType(null, new HashMap<>()));

    assertFalse("Should not accept Foo type.", formatter.acceptType(foo.referenceType(), new HashMap<>()));

    ObjectReference str = this.getObjectReference("java.lang.String");
    assertFalse("Should not accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>()));

    ObjectReference clz = this.getObjectReference("java.lang.Class");
    assertFalse("Should not accept Class type.", formatter.acceptType(clz.referenceType(), new HashMap<>()));

    LocalVariable list = this.getLocalVariable("strList");
    assertFalse("Should not accept List type.", formatter.acceptType(list.type(), new HashMap<>()));

    LocalVariable arrays = this.getLocalVariable("arrays");
    assertTrue("Should accept array type.", formatter.acceptType(arrays.type(), new HashMap<>()));
}
 
Example #6
Source File: ObjectFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    ObjectReference or = this.getObjectReference("Foo");

    assertFalse("Should not accept null type.", formatter.acceptType(null, new HashMap<>()));

    assertTrue("Should accept Foo type.", formatter.acceptType(or.referenceType(), new HashMap<>()));

    ObjectReference str = this.getObjectReference("java.lang.String");
    assertTrue("Should accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>()));

    ObjectReference clz = this.getObjectReference("java.lang.Class");
    assertTrue("Should accept Class type.", formatter.acceptType(clz.referenceType(), new HashMap<>()));

    LocalVariable list = this.getLocalVariable("strList");
    assertTrue("Should accept List type.", formatter.acceptType(list.type(), new HashMap<>()));

    LocalVariable arrays = this.getLocalVariable("arrays");
    assertTrue("Should accept array type.", formatter.acceptType(arrays.type(), new HashMap<>()));
}
 
Example #7
Source File: ClassObjectFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    ObjectReference foo = this.getObjectReference("Foo");

    assertFalse("Should not accept null type.", formatter.acceptType(null, new HashMap<>()));

    assertFalse("Should not accept Foo type.", formatter.acceptType(foo.referenceType(), new HashMap<>()));

    ObjectReference str = this.getObjectReference("java.lang.String");
    assertFalse("Should not accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>()));

    ObjectReference clz = this.getObjectReference("java.lang.Class");
    assertTrue("Should accept Class type.", formatter.acceptType(clz.referenceType(), new HashMap<>()));

    LocalVariable list = this.getLocalVariable("strList");
    assertFalse("Should not accept List type.", formatter.acceptType(list.type(), new HashMap<>()));

    LocalVariable arrays = this.getLocalVariable("arrays");
    assertFalse("Should not accept array type.", formatter.acceptType(arrays.type(), new HashMap<>()));
}
 
Example #8
Source File: NullObjectFormatterTest.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    ObjectReference foo = this.getObjectReference("Foo");

    assertTrue("Should accept null type.", formatter.acceptType(null, new HashMap<>()));

    assertFalse("Should not accept Foo type.", formatter.acceptType(foo.referenceType(), new HashMap<>()));

    ObjectReference str = this.getObjectReference("java.lang.String");
    assertFalse("Should not accept String type.", formatter.acceptType(str.referenceType(), new HashMap<>()));

    ObjectReference clz = this.getObjectReference("java.lang.Class");
    assertFalse("Should not accept Class type.", formatter.acceptType(clz.referenceType(), new HashMap<>()));

    LocalVariable list = this.getLocalVariable("strList");
    assertFalse("Should not accept List type.", formatter.acceptType(list.type(), new HashMap<>()));

    LocalVariable arrays = this.getLocalVariable("arrays");
    assertFalse("Should not accept array type.", formatter.acceptType(arrays.type(), new HashMap<>()));
}
 
Example #9
Source File: JDIExampleDebugger.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Displays the visible variables
 * @param event
 * @throws IncompatibleThreadStateException
 * @throws AbsentInformationException
 */
public void displayVariables(LocatableEvent event) throws IncompatibleThreadStateException, AbsentInformationException {
    StackFrame stackFrame = event.thread().frame(0);
    if(stackFrame.location().toString().contains(debugClass.getName())) {
        Map<LocalVariable, Value> visibleVariables = stackFrame.getValues(stackFrame.visibleVariables());
        System.out.println("Variables at " +stackFrame.location().toString() +  " > ");
        for (Map.Entry<LocalVariable, Value> entry : visibleVariables.entrySet()) {
            System.out.println(entry.getKey().name() + " = " + entry.getValue());
        }
    }
}
 
Example #10
Source File: DecisionProcedureGuidanceJDI.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
private com.sun.jdi.Value getJDIValueLocalVariable(String var) 
throws GuidanceException, IncompatibleThreadStateException, AbsentInformationException {
    final com.sun.jdi.Value val;
    if ("this".equals(var)) {
        val = rootFrameConcrete().thisObject();
    } else {
        final LocalVariable variable = rootFrameConcrete().visibleVariableByName(var); 
        if (variable == null) {
            throw new GuidanceException(ERROR_BAD_PATH + "{ROOT}:" + var + ".");
        }
        val = rootFrameConcrete().getValue(variable);
    }
    return val;
}
 
Example #11
Source File: NumericFormatterTest.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAcceptType() throws Exception {
    LocalVariable i = this.getLocalVariable("i");

    assertFalse("NumericFormatter should accept null.", formatter.acceptType(null, new HashMap<>()));
    assertTrue("NumericFormatter should accept int type.", formatter.acceptType(i.type(), new HashMap<>()));
    ObjectReference integer = this.getObjectReference("java.lang.Integer");
    assertFalse("NumericFormatter should not accept Integer type.", formatter.acceptType(integer.type(), new HashMap<>()));
    assertFalse("NumericFormatter should not accept Object type.", formatter.acceptType(this.getLocalVariable("obj").type(), new HashMap<>()));
    assertFalse("NumericFormatter should not accept array type.", formatter.acceptType(this.getLocalVariable("arrays").type(), new HashMap<>()));
    assertFalse("NumericFormatter should not accept String type.", formatter.acceptType(this.getLocalVariable("str").type(), new HashMap<>()));

    VirtualMachine vm = getVM();
    assertFalse("NumericFormatter should not accept boolean type.",
        formatter.acceptType(vm.mirrorOf(true).type(), new HashMap<>()));

    assertFalse("NumericFormatter should not accept char type.",
        formatter.acceptType(vm.mirrorOf('c').type(), new HashMap<>()));

    assertTrue("NumericFormatter should accept long type.",
        formatter.acceptType(vm.mirrorOf(1L).type(), new HashMap<>()));

    assertTrue("NumericFormatter should accept float type.",
        formatter.acceptType(vm.mirrorOf(1.2f).type(), new HashMap<>()));

    assertTrue("NumericFormatter should accept double type.",
        formatter.acceptType(vm.mirrorOf(1.2).type(), new HashMap<>()));

    assertTrue("NumericFormatter should accept byte type.",
        formatter.acceptType(vm.mirrorOf((byte)12).type(), new HashMap<>()));

    assertTrue("NumericFormatter should accept short type.",
        formatter.acceptType(vm.mirrorOf((short)12121).type(), new HashMap<>()));
}
 
Example #12
Source File: SetVariableRequestHandler.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
private Value handleSetValueForStackFrame(String name, String belongToClass, String valueString,
        boolean showStaticVariables, StackFrame container, Map<String, Object> options)
                throws AbsentInformationException, InvalidTypeException, ClassNotLoadedException {
    Value newValue;
    if (name.equals("this")) {
        throw new UnsupportedOperationException("SetVariableRequest: 'This' variable cannot be changed.");
    }
    LocalVariable variable = container.visibleVariableByName(name);
    if (StringUtils.isBlank(belongToClass) && variable != null) {
        newValue = this.setFrameValue(container, variable, valueString, options);
    } else {
        if (showStaticVariables && container.location().method().isStatic()) {
            ReferenceType type = container.location().declaringType();
            if (StringUtils.isBlank(belongToClass)) {
                Field field = type.fieldByName(name);
                newValue = setStaticFieldValue(type, field, name, valueString, options);
            } else {
                newValue = setFieldValueWithConflict(null, type.allFields(), name, belongToClass,
                        valueString, options);
            }
        } else {
            throw new UnsupportedOperationException(
                    String.format("SetVariableRequest: Variable %s cannot be found.", name));
        }
    }
    return newValue;
}
 
Example #13
Source File: ObjectLocalVariable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
ObjectLocalVariable (
    JPDADebuggerImpl debugger,
    ObjectReference value,
    String className,
    LocalVariable local,
    String genericSignature,
    CallStackFrameImpl frame
) {
    this(debugger, value, className, local, genericSignature,
         getID(local),
         frame);
}
 
Example #14
Source File: SetVariableRequestHandler.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
private Value setFrameValue(StackFrame frame, LocalVariable localVariable, String value, Map<String, Object> options)
        throws ClassNotLoadedException, InvalidTypeException {
    return setValueProxy(localVariable.type(), value, newValue -> frame.setValue(localVariable, newValue), options);
}
 
Example #15
Source File: EvaluationContext.java    From netbeans with Apache License 2.0 4 votes vote down vote up
LocalVarInf(LocalVariable var, EvaluationContext context) {
    this.var = var;
    this.context = context;
}
 
Example #16
Source File: EvaluationContext.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void putLocalVariable(Tree tree, LocalVariable var) {
    VariableInfo info = new VariableInfo.LocalVarInf(var, this);
    variables.put(tree, info);
}
 
Example #17
Source File: AbstractJdiTestCase.java    From java-debug with Eclipse Public License 1.0 4 votes vote down vote up
protected LocalVariable getLocalVariable(String name) throws AbsentInformationException {
    StackFrame frame = getStackFrame();
    return frame.visibleVariableByName(name);
}
 
Example #18
Source File: JPDADebuggerImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Variable getLocalVariable(JPDAThread thread, LocalVariable lv, Value v) {
    return (Variable) localsTranslation.translateOnThread(thread, lv, v);
}