/** * Creates an {@link IValue} for the given {@link EObject}. * * @param referenceTypeName * the reference type name * @param value * the {@link EObject} * @return the created {@link IValue} */ private IValue createEObjectValue(String referenceTypeName, EObject value) { final IValue res; DSLEObjectValueAdapter valueAdapter = null; synchronized(value) { for (Adapter adapter : value.eAdapters()) { if (adapter.isAdapterForType(IValue.class)) { valueAdapter = (DSLEObjectValueAdapter)adapter; break; } } if (valueAdapter == null) { valueAdapter = new DSLEObjectValueAdapter(this, referenceTypeName, value); value.eAdapters().add(valueAdapter); } } res = valueAdapter; return res; }
/** * Gets the expression display name * * @param expression * @return * @throws DebugException */ private String getExpressionText( IExpression expression ) throws DebugException { StringBuffer buff = new StringBuffer( ); IValue javaValue = expression.getValue( ); buff.append( '"' + expression.getExpressionText( ) + '"' ); if ( javaValue != null ) { String valueString = getValueText( javaValue ); if ( valueString.length( ) > 0 ) { buff.append( "= " ); //$NON-NLS-1$ buff.append( valueString ); } } return buff.toString( ); }
/** * Render a selected variable. * * @param selection * the selection object * @param element * the variable element * @throws DebugException */ private void displayVariable(IStructuredSelection selection, IDebugElement element) throws DebugException { IValue value = ((IVariable) element).getValue(); if (value instanceof IJavaPrimitiveValue) { setBrowserTextToPrimitive((IJavaPrimitiveValue) value); } else { TreePath firstElementTreePath = ((TreeSelection) selection).getPaths()[0]; String watchExpression = generateWatchExpression(firstElementTreePath); String messageExpression = generateMessageExpression(watchExpression); // Iterate all threads and run our rendering // expression in them in the hopes that we can find // the relevant selection in only one thread // FIXME find a better way to derive the correct thread! IWatchExpressionDelegate delegate = DebugPlugin.getDefault().getExpressionManager() .newWatchExpressionDelegate(element.getModelIdentifier()); for (IThread thread : element.getDebugTarget().getThreads()) { delegate.evaluateExpression(messageExpression, thread, this); } } }
/** * Gets the {@link IValue} for the given {@link Object}. * * @param referenceTypeName * the reference type name * @param value * the {@link Object value} * @return the corresponding {@link IValue} */ public IValue getValue(String referenceTypeName, Object value) { final IValue res; if (value instanceof EObject) { res = createEObjectValue(referenceTypeName, (EObject)value); } else if (value instanceof Collection<?>) { res = new DSLArrayValue(this, referenceTypeName, ((Collection<?>)value).toArray()); } else if (value instanceof Object[]) { res = new DSLArrayValue(this, referenceTypeName, (Object[])value); } else if (value instanceof byte[]) { res = createByteArrayValue(referenceTypeName, (byte[])value); } else if (value instanceof short[]) { res = createShortArrayValue(referenceTypeName, (short[])value); } else if (value instanceof int[]) { res = createIntegerArrayValue(referenceTypeName, (int[])value); } else if (value instanceof long[]) { res = createLongArrayValue(referenceTypeName, (long[])value); } else if (value instanceof float[]) { res = createFloatArrayValue(referenceTypeName, (float[])value); } else if (value instanceof double[]) { res = createDoubleArrayValue(referenceTypeName, (double[])value); } else if (value instanceof char[]) { res = createCharacterArrayValue(referenceTypeName, (char[])value); } else if (value instanceof boolean[]) { res = createBooleanArrayValue(referenceTypeName, (boolean[])value); } else if (value == null) { res = new DSLNullValue(this, referenceTypeName); } else { res = new DSLObjectValue(this, referenceTypeName, value); } return res; }
/** * Creates an {@link IValue} for a byte[]. * * @param referenceTypeName * the reference type name * @param value * the byte[] * @return the created {@link IValue} */ private IValue createByteArrayValue(String referenceTypeName, byte[] value) { final IValue res; Byte[] array = new Byte[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Byte.valueOf(value[i]); } res = new DSLByteArrayValue(this, referenceTypeName, array); return res; }
/** * Creates an {@link IValue} for a short[]. * * @param referenceTypeName * the reference type name * @param value * the short[] * @return the created {@link IValue} */ private IValue createShortArrayValue(String referenceTypeName, short[] value) { final IValue res; Short[] array = new Short[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Short.valueOf(value[i]); } res = new DSLShortArrayValue(this, referenceTypeName, array); return res; }
/** * Creates an {@link IValue} for a int[]. * * @param referenceTypeName * the reference type name * @param value * the int[] * @return the created {@link IValue} */ private IValue createIntegerArrayValue(String referenceTypeName, int[] value) { final IValue res; Integer[] array = new Integer[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Integer.valueOf(value[i]); } res = new DSLIntArrayValue(this, referenceTypeName, array); return res; }
/** * Creates an {@link IValue} for a long[]. * * @param referenceTypeName * the reference type name * @param value * the long[] * @return the created {@link IValue} */ private IValue createLongArrayValue(String referenceTypeName, long[] value) { final IValue res; Long[] array = new Long[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Long.valueOf(value[i]); } res = new DSLLongArrayValue(this, referenceTypeName, array); return res; }
/** * Creates an {@link IValue} for a float[]. * * @param referenceTypeName * the reference type name * @param value * the float[] * @return the created {@link IValue} */ private IValue createFloatArrayValue(String referenceTypeName, float[] value) { final IValue res; Float[] array = new Float[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Float.valueOf(value[i]); } res = new DSLFloatArrayValue(this, referenceTypeName, array); return res; }
/** * Creates an {@link IValue} for a double[]. * * @param referenceTypeName * the reference type name * @param value * the double[] * @return the created {@link IValue} */ private IValue createDoubleArrayValue(String referenceTypeName, double[] value) { final IValue res; Double[] array = new Double[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Double.valueOf(value[i]); } res = new DSLDoubleArrayValue(this, referenceTypeName, array); return res; }
/** * Creates an {@link IValue} for a char[]. * * @param referenceTypeName * the reference type name * @param value * the char[] * @return the created {@link IValue} */ private IValue createCharacterArrayValue(String referenceTypeName, char[] value) { final IValue res; Character[] array = new Character[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Character.valueOf(value[i]); } res = new DSLCharArrayValue(this, referenceTypeName, array); return res; }
/** * Creates an {@link IValue} for a boolean[]. * * @param referenceTypeName * the reference type name * @param value * the boolean[] * @return the created {@link IValue} */ private IValue createBooleanArrayValue(String referenceTypeName, boolean[] value) { final IValue res; Boolean[] array = new Boolean[value.length]; for (int i = 0; i < value.length; ++i) { array[i] = Boolean.valueOf(value[i]); } res = new DSLBooleanArrayValue(this, referenceTypeName, array); return res; }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue) */ public boolean verifyValue(IValue value) throws DebugException { Object response = factory.getDebugger().handleEvent( new ValidateVariableValueRequest(ThreadUtils.getThread(getHost().getFrame()).getName(), getHost().getFrame().getName(), getHost().getName(), value.getValueString())); return Boolean.TRUE == response; }
private static String getUnitFromTopStackFrame(IJavaThread thread) throws CoreException { if (!thread.hasStackFrames()) { return null; } IStackFrame top = thread.getTopStackFrame(); if (top.getVariables().length > 0) { for (IVariable var : top.getVariables()) { try { IValue value = var.getValue(); if (value instanceof IJavaValue) { IJavaObject javaValue = (IJavaObject) value; IJavaDebugTarget debugTarget = thread.getDebugTarget().getAdapter(IJavaDebugTarget.class); IJavaValue arg = debugTarget.newValue("Fully Qualified Name"); // the signature (2nd argument) can be retrieved with javap. Unit extends soot.tagkit.Host for the tag support // -> javap -cp soot-trunk.jar -s soot.tagkit.Host // the signature is in the output under "descriptor" IJavaType type = javaValue.getJavaType(); if (isTagHost(type)) { // check, if this is a unit, which contains Tags IJavaValue fqnTag = javaValue.sendMessage("getTag", "(Ljava/lang/String;)Lsoot/tagkit/Tag;", new IJavaValue[] { arg }, thread, false); IJavaValue tagValue = ((IJavaObject) fqnTag).sendMessage("getValue", "()[B", new IJavaValue[0], thread, false); IJavaArray byteArray = (IJavaArray) tagValue; byte[] b = new byte[byteArray.getLength()]; for (int i = 0; i < b.length; i++) { IJavaPrimitiveValue byteValue = (IJavaPrimitiveValue) byteArray.getValue(i); b[i] = byteValue.getByteValue(); } String currentUnitFqn = new String(b); return currentUnitFqn; } } } catch (Exception e) { logger.error("Couldn't retrieve variable " + var.getName() + " from top stack frame", e); } } } return null; }
@Override public IValue getValue() throws DebugException { InterpreterState lastState = this.getDebugTarget().getProcess().getProcessListener().getSuspendedState(); int pointer = this.getIntValue(); if (lastState != null && pointer > -1) { return new BfValue(this.getDebugTarget(), pointer, this.renderToHex()); } return null; }
@Override public boolean verifyValue(IValue value) throws DebugException { ValueBase valueBase = ValueBase.cast(value); if (valueBase == null) { return false; } Value realValue = valueBase.asRealValue(); if (realValue == null) { return false; } return true; }
@Override public void setValue(IValue value) throws DebugException { ValueBase valueBase = ValueBase.cast(value); if (valueBase == null) { throw new IllegalArgumentException("Unrecognized type of value"); } Value realValue = valueBase.asRealValue(); if (realValue == null) { throw new IllegalArgumentException("Not a real value"); } JsValue jsValue = realValue.getJsValue(); setValue(jsValue); }
/** * Downcasts IValue to ValueBase if possible or returns null. This should be used in context * where IValue is available, but it's unknown whether it's Chromium value or not. * Clients should use this method rather that do instanceof themselves, because the latter is * unsafe technique (you cannot track manual downcasts and consequently cannot refactor/manage * them). */ public static ValueBase cast(IValue value) { if (value instanceof ValueBase) { return (ValueBase) value; } else { return null; } }
@Override public VariableWrapper castElement(Object element) { if (element instanceof IWatchExpression == false) { return null; } final IWatchExpression watchExpression = (IWatchExpression) element; return new VariableWrapper() { @Override public Value getValue() { IValue value = watchExpression.getValue(); if (value instanceof Value == false) { return null; } Value chromiumValue = (Value) value; return chromiumValue; } @Override public Variable getVariable() { return null; } @Override public IDebugElement getDebugElement() { return watchExpression; } @Override public ConnectedTargetData getConnectedTargetData() { IDebugTarget debugTarget = watchExpression.getDebugTarget(); if (debugTarget instanceof DebugTargetImpl == false) { return null; } DebugTargetImpl debugTargetImpl = (DebugTargetImpl) debugTarget; return debugTargetImpl.getConnectedOrNull(); } }; }
public IDebugTarget getDebugTarget() { IValue value = getValue(); if (value != null) { return value.getDebugTarget(); } return null; }
/** * Determine whether the given value contains a variable with the given name. * * @param value a value * @param name a variable name * @return true if the value contains a variable with the given name * @throws DebugException if accessing the debug model fails */ protected final boolean hasNamedVariable(IValue value, String name) throws DebugException { for (IVariable v : value.getVariables()) { if (v.getName().equals(name)) { return true; } } return false; }
/** * Retrieve a variable with given name referenced from the given value. * * @param value a value * @param name the name of a variable referenced by {@code value} * @return the first variable matching the given name * @throws DebugException if accessing the debug model fails */ protected final IVariable getNamedVariable(IValue value, String name) throws DebugException { for (IVariable v : value.getVariables()) { if (v.getName().equals(name)) { return v; } } throw new IllegalArgumentException("The given variable name was not found: " + name); }
public void computeDetail( IValue value, IValueDetailListener listener ) { // show the string when mouse hover at the value in the watch view. String detail = ""; //$NON-NLS-1$ try { detail = value.getValueString( ); } catch ( DebugException e ) { } listener.detailComputed( value, detail ); }
/** * @param value * @return * @throws DebugException */ private String getValueText( IValue value ) throws DebugException { String refTypeName = value.getReferenceTypeName( ); String valueString = value.getValueString( ); boolean isString = false; // boolean isObject = true; // boolean isArray = value instanceof IJavaArray; StringBuffer buffer = new StringBuffer( ); // Always show type name for objects & arrays (but not Strings) if ( !isString && ( refTypeName.length( ) > 0 ) ) { String qualTypeName = refTypeName; buffer.append( qualTypeName ); buffer.append( ' ' ); } // Put double quotes around Strings if ( valueString != null && ( isString || valueString.length( ) > 0 ) ) { if ( isString ) { buffer.append( '"' ); } buffer.append( valueString ); if ( isString ) { buffer.append( '"' ); } } return buffer.toString( ); }
/** * Render a watch expression. * * FIXME we don't treat watch expression yet, this will just render their * {@link String} value. * * @param element * the expression element */ private void displayExpression(IDebugElement element) { IValue value = ((IExpression) element).getValue(); if (value instanceof IJavaPrimitiveValue) { setBrowserTextToPrimitive((IJavaPrimitiveValue) value); } else if (value instanceof IJavaObject) { setBrowserTextToString(value.toString()); } else if (value != null) { setBrowserTextToString(value.toString(), "Error!"); } }
@Override public boolean hasChildren(Object element) { if (element instanceof List) { List list = (List) element; return list.size() > 0; } if (element instanceof IValue) { try { return ((IValue) element).hasVariables(); } catch (DebugException e) { Log.log(e); } } return true; }
@Override public IValue getValue() { synchronized (variables) { if (variables.length == 0) { variables = new PyVariable[1]; variables[0] = new PyVariable((AbstractDebugTarget) context.getDebugTarget(), "Error", "pydev ERROR", "Could not resolve variable", null); } return variables[0]; } }
/** * We've got some work to do to replicate here, because we can't return null, and have LazyModel presentation do the * default */ @Override public void computeDetail(IValue value, IValueDetailListener listener) { if (value instanceof PyVariable) { try { ((PyVariable) value).getVariables(); listener.detailComputed(value, ((PyVariable) value).getDetailText()); } catch (DebugException e) { PydevDebugPlugin.errorDialog("Unexpected error fetching variable", e); } } }
/** * This hack just creates a Watch expression, gets result and removes the watch expression. * This is simple, since the watch functionality is already there. * * @see WatchExpressionAction#createExpression */ private void eval(final String expr) { final IWatchExpression expression = createWatchExpression(expr); final Shell shell = PydevDebugPlugin.getActiveWorkbenchWindow().getShell(); Display display = PydevDebugPlugin.getDefault().getWorkbench().getDisplay(); final Point point = display.getCursorLocation(); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { expression.evaluate(); waitForExpressionEvaluation(expression); try { IValue value = expression.getValue(); String result = null; if (value != null) { result = expr + "\n" + value.getValueString(); DisplayPopup popup = new DisplayPopup(shell, point, result); popup.open(); } } catch (DebugException e) { DebugPlugin.log(e); return; } catch (Throwable t) { DebugPlugin.log(t); } } }); }