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); } }
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; }
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; }
/** * Build the visible variable map. * Need not be synchronized since it cannot be provably stale. */ private void createVisibleVariables() throws AbsentInformationException { if (visibleVariables == null) { List<LocalVariable> allVariables = location.method().variables(); Map<String, LocalVariable> map = new HashMap<>(allVariables.size()); for (LocalVariable variable : allVariables) { String name = variable.name(); if (variable.isVisible(this)) { LocalVariable existing = map.get(name); if ((existing == null) || ((LocalVariableImpl)variable).hides(existing)) { map.put(name, variable); } } } visibleVariables = map; } }
@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<>())); }
@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<>())); }
@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<>())); }
@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<>())); }
@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<>())); }
@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<>())); }
public Map<LocalVariable, Value> getValues(List<? extends LocalVariable> vars) { Map<LocalVariable, LocalVariable> fieldMap = new HashMap<LocalVariable, LocalVariable>(); List<LocalVariable> unwrappedLocalVariables = new ArrayList<LocalVariable>(); for (LocalVariable var : vars) { LocalVariable unwrapped = F3Wrapper.unwrap(var); if (isF3SyntheticLocalVar(unwrapped.name())) { throw new IllegalArgumentException("invalid var: " + var.name()); } unwrappedLocalVariables.add(unwrapped); fieldMap.put(unwrapped, var); } Map<LocalVariable, Value> fieldValues = underlying().getValues(unwrappedLocalVariables); Map<LocalVariable, Value> result = new HashMap<LocalVariable, Value>(); for (Map.Entry<LocalVariable, Value> entry: fieldValues.entrySet()) { result.put(fieldMap.get(entry.getKey()), entry.getValue()); } return result; }
@Test(timeout=5000) public void testHello1() { try { compile("LocalVar.f3"); stop("in LocalVar.f3$run$"); f3run(); BreakpointEvent bkpt = resumeToBreakpoint(); // We hide F3 synthetic variables. F3StackFrame frame = (F3StackFrame) bkpt.thread().frame(0); LocalVariable var = frame.visibleVariableByName("_$UNUSED$_$ARGS$_"); Assert.assertNull(var); // underlying (java) frame object exposes this variable. StackFrame jframe = F3Wrapper.unwrap(frame); var = jframe.visibleVariableByName("_$UNUSED$_$ARGS$_"); Assert.assertNotNull(var); resumeToVMDeath(); quit(); } catch (Exception exp) { exp.printStackTrace(); Assert.fail(exp.getMessage()); } }
private void createVariable(final LocalVariable var, final int lineFrom, final int lineTo, final IMethodNode methodNode) { ITypeNodeRef varTypeNode; try { varTypeNode = upstream.resolveType(var.type().signature(), var.typeName()); } catch (final ClassNotLoadedException e) { varTypeNode = modelFactory().lookupTypeRefByName(var.typeName()); } methodNode.addDataMember(var.name(), lineFrom, lineTo, varTypeNode, NO_JDI, createModifiers(var), NodeVisibility.NV_LOCAL, model.valueFactory() .createUninitializedValue()); }
public Long getMethodId(final Method method) { final String sig = Signatures.getPrefixed(method); Long id = store.get(sig); if (id != null) { return id; } id = register(Signatures.PREFIX_METHOD, sig, METHOD_ID.incrementAndGet()); try { if (method != null) { for (final LocalVariable v : method.variables()) { getVariableId(v); } } } catch (final AbsentInformationException ignored) { } return id; }
ObjectLocalVariable ( JPDADebuggerImpl debugger, ObjectReference value, String className, LocalVariable local, String genericSignature, CallStackFrameImpl frame ) { this(debugger, value, className, local, genericSignature, getID(local), frame); }
public int compareTo(LocalVariable object) { LocalVariableImpl other = (LocalVariableImpl)object; int rc = scopeStart.compareTo(other.scopeStart); if (rc == 0) { rc = slot() - other.slot(); } return rc; }
boolean hides(LocalVariable other) { LocalVariableImpl otherImpl = (LocalVariableImpl)other; if (!method.equals(otherImpl.method) || !name.equals(otherImpl.name)) { return false; } else { return (scopeStart.compareTo(otherImpl.scopeStart) > 0); } }
public List<LocalVariable> variablesByName(String name) throws AbsentInformationException { List<LocalVariable> variables = getVariables(); List<LocalVariable> retList = new ArrayList<>(2); Iterator<LocalVariable> iter = variables.iterator(); while(iter.hasNext()) { LocalVariable variable = iter.next(); if (variable.name().equals(name)) { retList.add(variable); } } return retList; }
public List<LocalVariable> arguments() throws AbsentInformationException { List<LocalVariable> variables = getVariables(); List<LocalVariable> retList = new ArrayList<>(variables.size()); Iterator<LocalVariable> iter = variables.iterator(); while(iter.hasNext()) { LocalVariable variable = iter.next(); if (variable.isArgument()) { retList.add(variable); } } return retList; }
private List<LocalVariable> getVariables() throws AbsentInformationException { if (absentVariableInformation) { throw new AbsentInformationException(); } List<LocalVariable> variables = (variablesRef == null) ? null : variablesRef.get(); if (variables != null) { return variables; } variables = getVariables1(); variables = Collections.unmodifiableList(variables); variablesRef = new SoftReference<>(variables); return variables; }
/** * Return the list of visible variable in the frame. * Need not be synchronized since it cannot be provably stale. */ public List<LocalVariable> visibleVariables() throws AbsentInformationException { validateStackFrame(); createVisibleVariables(); List<LocalVariable> mapAsList = new ArrayList<>(visibleVariables.values()); Collections.sort(mapAsList); return mapAsList; }
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; }
public LocalVariableProxyImpl(StackFrameProxyImpl frame, LocalVariable variable) { super(frame.myTimer); myFrame = frame; myVariableName = variable.name(); myTypeName = variable.typeName(); myVariable = variable; }
public LocalVariable getVariable() throws EvaluateException { checkValid(); if (myVariable == null) { myVariable = myFrame.visibleVariableByNameInt(myVariableName); if (myVariable == null) { //myFrame is not this variable's frame throw EvaluateExceptionUtil.createEvaluateException(new IncompatibleThreadStateException()); } } return myVariable; }
public static List<LocalVariable> wrapLocalVariables(F3VirtualMachine f3vm, List<LocalVariable> locals) { if (locals == null) { return null; } List<LocalVariable> result = new ArrayList<LocalVariable>(locals.size()); for (LocalVariable var: locals) { result.add(wrap(f3vm, var)); } return result; }
public List<LocalVariable> visibleVariables() throws AbsentInformationException { List<LocalVariable> locals = underlying().visibleVariables(); List<LocalVariable> result = new ArrayList<LocalVariable>(); for (LocalVariable var : locals) { if (! isF3SyntheticLocalVar(var.name())) { result.add(F3Wrapper.wrap(virtualMachine(), var)); } } return result; }
public LocalVariable getVariable() throws EvaluateException { checkValid(); if(myVariable == null) { myVariable = myFrame.visibleVariableByNameInt(myVariableName); if(myVariable == null) { //myFrame is not this variable's frame throw EvaluateExceptionUtil.createEvaluateException(new IncompatibleThreadStateException()); } } return myVariable; }
private Set<NodeModifier> createModifiers(final LocalVariable var) { final Set<NodeModifier> modifiers = new LinkedHashSet<NodeModifier>(); // final if (var.isArgument()) { modifiers.add(NM_ARGUMENT); } return modifiers; }
public Long getVariableId(final LocalVariable variable) { final String sig = Signatures.getPrefixed(variable); final Long id = store.get(sig); if (id != null) { return id; } return register(Signatures.PREFIX_VARIABLE, sig, VARIABLE_ID.incrementAndGet()); }
public Variable getLocalVariable(JPDAThread thread, LocalVariable lv, Value v) { return (Variable) localsTranslation.translateOnThread(thread, lv, v); }
public void putLocalVariable(Tree tree, LocalVariable var) { VariableInfo info = new VariableInfo.LocalVarInf(var, this); variables.put(tree, info); }
LocalVarInf(LocalVariable var, EvaluationContext context) { this.var = var; this.context = context; }
public List<LocalVariable> variables() throws AbsentInformationException { return getVariables(); }
private List<LocalVariable> getVariables1_4() throws AbsentInformationException { JDWP.Method.VariableTable vartab = null; try { vartab = JDWP.Method.VariableTable. process(vm, declaringType, ref); } catch (JDWPException exc) { if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) { absentVariableInformation = true; throw new AbsentInformationException(); } else { throw exc.toJDIException(); } } // Get the number of slots used by argument variables argSlotCount = vartab.argCnt; int count = vartab.slots.length; List<LocalVariable> variables = new ArrayList<>(count); for (int i=0; i<count; i++) { JDWP.Method.VariableTable.SlotInfo si = vartab.slots[i]; /* * Skip "this*" entries because they are never real * variables from the JLS perspective. */ if (!si.name.startsWith("this$") && !si.name.equals("this")) { Location scopeStart = new LocationImpl(virtualMachine(), this, si.codeIndex); Location scopeEnd = new LocationImpl(virtualMachine(), this, si.codeIndex + si.length - 1); LocalVariable variable = new LocalVariableImpl(virtualMachine(), this, si.slot, scopeStart, scopeEnd, si.name, si.signature, null); // Add to the variable list variables.add(variable); } } return variables; }
private List<LocalVariable> getVariables1() throws AbsentInformationException { if (!vm.canGet1_5LanguageFeatures()) { return getVariables1_4(); } JDWP.Method.VariableTableWithGeneric vartab = null; try { vartab = JDWP.Method.VariableTableWithGeneric. process(vm, declaringType, ref); } catch (JDWPException exc) { if (exc.errorCode() == JDWP.Error.ABSENT_INFORMATION) { absentVariableInformation = true; throw new AbsentInformationException(); } else { throw exc.toJDIException(); } } // Get the number of slots used by argument variables argSlotCount = vartab.argCnt; int count = vartab.slots.length; List<LocalVariable> variables = new ArrayList<LocalVariable>(count); for (int i=0; i<count; i++) { JDWP.Method.VariableTableWithGeneric.SlotInfo si = vartab.slots[i]; /* * Skip "this*" entries because they are never real * variables from the JLS perspective. */ if (!si.name.startsWith("this$") && !si.name.equals("this")) { Location scopeStart = new LocationImpl(virtualMachine(), this, si.codeIndex); Location scopeEnd = new LocationImpl(virtualMachine(), this, si.codeIndex + si.length - 1); LocalVariable variable = new LocalVariableImpl(virtualMachine(), this, si.slot, scopeStart, scopeEnd, si.name, si.signature, si.genericSignature); // Add to the variable list variables.add(variable); } } return variables; }
/** * Return a particular variable in the frame. * Need not be synchronized since it cannot be provably stale. */ public LocalVariable visibleVariableByName(String name) throws AbsentInformationException { validateStackFrame(); createVisibleVariables(); return visibleVariables.get(name); }
public Value getValue(LocalVariable variable) { List<LocalVariable> list = new ArrayList<>(1); list.add(variable); return getValues(list).get(variable); }
public void setValue(LocalVariable variableIntf, Value valueIntf) throws InvalidTypeException, ClassNotLoadedException { validateStackFrame(); validateMirror(variableIntf); validateMirrorOrNull(valueIntf); LocalVariableImpl variable = (LocalVariableImpl)variableIntf; ValueImpl value = (ValueImpl)valueIntf; if (!variable.isVisible(this)) { throw new IllegalArgumentException(variable.name() + " is not valid at this frame location"); } try { // Validate and convert value if necessary value = ValueImpl.prepareForAssignment(value, variable); JDWP.StackFrame.SetValues.SlotInfo[] slotVals = new JDWP.StackFrame.SetValues.SlotInfo[1]; slotVals[0] = new JDWP.StackFrame.SetValues. SlotInfo(variable.slot(), value); PacketStream ps; /* protect against defunct frame id */ synchronized (vm.state()) { validateStackFrame(); ps = JDWP.StackFrame.SetValues. enqueueCommand(vm, thread, id, slotVals); } /* actually set it, now that order is guaranteed */ try { JDWP.StackFrame.SetValues.waitForReply(vm, ps); } catch (JDWPException exc) { switch (exc.errorCode()) { case JDWP.Error.INVALID_FRAMEID: case JDWP.Error.THREAD_NOT_SUSPENDED: case JDWP.Error.INVALID_THREAD: throw new InvalidStackFrameException(); default: throw exc.toJDIException(); } } } catch (ClassNotLoadedException e) { /* * Since we got this exception, * the variable type must be a reference type. The value * we're trying to set is null, but if the variable's * class has not yet been loaded through the enclosing * class loader, then setting to null is essentially a * no-op, and we should allow it without an exception. */ if (value != null) { throw e; } } }
public List<LocalVariable> variables() throws AbsentInformationException { throw new AbsentInformationException(); }