private Set<IJavaObject> getAllReachableObjects(SubMonitor monitor) { try { Set<IJavaObject> objs = new HashSet<IJavaObject>(); getReachableObjects(stack.getThis(), objs); for (IVariable var: stack.getLocalVariables()) getReachableObjects((IJavaValue)var.getValue(), objs); for (ReferenceType type: getAllLoadedTypes(stack)) { for (Field field: type.allFields()) if (field.isStatic() && isUsefulStaticDFSField(type.name(), field)) getReachableObjects(JDIValue.createValue((JDIDebugTarget)stack.getDebugTarget(), type.getValue(field)), objs); monitor.worked(1); } return objs; } catch (DebugException e) { throw new RuntimeException(e); } }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.IStackFrame#getVariables() */ public IVariable[] getVariables() throws DebugException { final List<IVariable> res = new ArrayList<IVariable>(); for (Variable variable : getHost().getVariables()) { synchronized(variable) { final IVariable var = (IVariable)factory.adapt(variable, IVariable.class); if (var != null) { res.add(var); } else { throw new IllegalStateException("can't addapt Variable to IVariable."); } } } return res.toArray(new IVariable[res.size()]); }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.IValue#getValueString() */ public String getValueString() throws DebugException { StringBuilder builder = new StringBuilder(BUFFER_SIZE); builder.append('['); if (variables.length > 0) { for (IVariable variable : variables) { builder = builder.append(variable.getValue().getValueString()); builder = builder.append(", "); } builder = builder.delete(builder.length() - ", ".length(), builder.length()); } builder.append(']'); return builder.toString(); }
private void handleVariables() throws DebugException { handleOutOfScopeVars(); for(IVariable v : frame.getVariables()) { IJavaVariable jv = (IJavaVariable) v; String varName = v.getName(); if(varName.equals("this")) { for (IVariable iv : jv.getValue().getVariables()) { IJavaVariable att = (IJavaVariable) iv; if(!att.isSynthetic() && !att.isStatic()) { handleVar(att, true); } } } else if(!jv.isSynthetic()) { handleVar(jv, false); } } }
private void handleOutOfScopeVars() throws DebugException { Iterator<Entry<String, IVariableModel<?>>> iterator = stackVars.entrySet().iterator(); while(iterator.hasNext()) { Entry<String, IVariableModel<?>> e = iterator.next(); String varName = e.getKey(); boolean contains = false; for(IVariable v : frame.getVariables()) { if(v.getName().equals(varName)) contains = true; // else if(v.getName().equals("this")) { // for (IVariable iv : v.getValue().getVariables()) // if(iv.getName().equals(varName)) // contains = true; // } } if(!contains) { e.getValue().setOutOfScope(); iterator.remove(); setChanged(); notifyObservers(new StackEvent<IVariableModel<?>>(StackEvent.Type.VARIABLE_OUT_OF_SCOPE, e.getValue())); } } }
public IVariable[] getVariables() throws DebugException { try { // TODO: support clearing with cache clear. IVariable[] result = variablesRef.get(); if (result != null) { return result; } IVariable[] variables = calculateVariables(); variablesRef.compareAndSet(null, variables); return variablesRef.get(); } catch (RuntimeException e) { // Log it, because Eclipse is likely to ignore it. ChromiumDebugPlugin.log(e); // We shouldn't throw RuntimeException from here, because calling // ElementContentProvider#update will forget to call update.done(). throw new DebugException(new Status(IStatus.ERROR, ChromiumDebugPlugin.PLUGIN_ID, "Failed to read variables", e)); //$NON-NLS-1$ } }
public KNode transform(final IVariable variable) { DebuKVizDialog.resetShown(); // Generate a top-level KNode and set some layout options KNode graph = KGraphUtil.createInitializedNode(); graph.setProperty(CoreOptions.DIRECTION, Direction.DOWN); graph.setProperty(LayeredOptions.NODE_PLACEMENT_STRATEGY, NodePlacementStrategy.LINEAR_SEGMENTS); // Generate a transformation context VariableTransformationContext context = new VariableTransformationContext(); // Start the mighty transformation! try { VariableTransformation.invokeFor(variable, graph, context); } catch (DebugException e) { StatusManager.getManager().handle(new Status( Status.ERROR, DebuKVizPlugin.PLUGIN_ID, "Error accessing the Eclipse debug framework.", e)); } return graph; }
/** * 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); } } }
@Override public boolean hasChildren(Object element) { try { if (element instanceof XMLToReferrersInfo) { return true; } if (element instanceof IVariable) { Object[] objects = childrenCache.get(element); if (objects != null && objects.length > 0) { return true; } IVariable iVariable = (IVariable) element; return iVariable.getValue().hasVariables(); } } catch (Exception e) { Log.log(e); } return false; }
PyVariable[] setVariables(PyVariable[] newVars) { IVariable[] oldVars = this.variables; if (newVars == oldVars) { return newVars; } IVariablesContainerParent p = this.parent.get(); if (p == null) { return newVars; } AbstractDebugTarget target = p.getTarget(); this.variables = newVars; if (!gettingInitialVariables) { if (target != null) { target.fireEvent(new DebugEvent(p, DebugEvent.CHANGE, DebugEvent.CONTENT)); } } return newVars; }
public IVariable[] getVariables() throws DebugException { // System.out.println("get variables: " + super.toString() + " initial: " + this.variables); if (onAskGetNewVars) { synchronized (lock) { //double check idiom for accessing onAskGetNewVars. if (onAskGetNewVars) { gettingInitialVariables = true; try { PyVariable[] vars = variablesLoader.fetchVariables(); setVariables(vars); // Important: only set to false after variables have been set. onAskGetNewVars = false; } finally { gettingInitialVariables = false; } } } } return this.variables; }
private static void handle(IVariable variable, String path, Shell shell, Matcher matcher, IJavaStackFrame stack) throws DebugException { IJavaType varType = EclipseUtils.getTypeOfVariableAndLoadIfNeeded((IJavaVariable)variable, stack); String varTypeName = EclipseUtils.sanitizeTypename(varType.getName()); String initValue = ""; if (matcher != null) { if (!matcher.group(2).equals(variable.getName())) { EclipseUtils.showError("Illegal variable.", "The first argument to the pdspec method, " + matcher.group(2) + ", must be the same as the variable on which you right-clicked, " + variable.getName() + ".", null); return; } initValue = matcher.group(1); if (initValue == null) initValue = varTypeName; } else initValue = varTypeName; InitialSynthesisDialog dialog = new InitialSynthesisDialog(shell, varTypeName, varType, stack, new TypePropertyDialog(path, varTypeName, stack, initValue, null), new SynthesisWorker(path, varType)); Synthesizer.synthesizeAndInsertStatements(variable, path, dialog, stack, matcher != null); }
private static void handle(IVariable variable, String path, Shell shell, Matcher matcher, IJavaStackFrame stack) throws DebugException { String initValue = null; if (matcher != null) { if (!matcher.group(1).equals(variable.getName())) { EclipseUtils.showError("Illegal variable.", "The first argument to the value method, " + matcher.group(1) + ", must be the same as the variable on which you right-clicked, " + variable.getName() + ".", null); return; } initValue = matcher.group(2); } else initValue = ""; IJavaType varType = EclipseUtils.getTypeOfVariableAndLoadIfNeeded((IJavaVariable)variable, stack); String varTypeName = EclipseUtils.sanitizeTypename(varType.getName()); PropertyDialog propertyDialog = null; if (EclipseUtils.isObject(variable)) propertyDialog = new ObjectValuePropertyDialog(path, varTypeName, stack, initValue, null); else if (EclipseUtils.isArray(variable)) propertyDialog = new ArrayValuePropertyDialog(path, varTypeName, stack, initValue, null); else propertyDialog = new PrimitiveValuePropertyDialog(path, varTypeName, stack, initValue, null); InitialSynthesisDialog dialog = new InitialSynthesisDialog(shell, varTypeName, varType, stack, propertyDialog, new SynthesisWorker(path, varType)); Synthesizer.synthesizeAndInsertStatements(variable, path, dialog, stack, initValue.length() > 0); }
/** * Initializes {@link DSLEclipseDebugIntegration#SUPPORTED_TYPES}. * * @return the {@link Set} of * {@link org.eclipse.emf.common.notify.AdapterFactory#isFactoryForType(Object) supported * types}. */ private static Set<Object> initSupportedTypes() { final Set<Object> res = new HashSet<Object>(); res.add(IThread.class); res.add(IDebugTarget.class); res.add(IStackFrame.class); res.add(IVariable.class); res.add(IBreakpoint.class); return res; }
/** * Gets an {@link IVariable} form a {@link Variable}. * * @param variable * the {@link Variable} * @return the {@link IVariable} */ public DSLVariableAdapter getVariable(Variable variable) { synchronized(variable) { final DSLVariableAdapter res = (DSLVariableAdapter)adapt(variable, IVariable.class); if (res == null) { throw new IllegalStateException("can't addapt Variable to IVariable."); } return res; } }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.IValue#getVariables() */ public IVariable[] getVariables() throws DebugException { IVariable[] res = new IVariable[getHost().eClass().getEAllStructuralFeatures().size()]; int i = 0; for (EStructuralFeature feature : getHost().eClass().getEAllStructuralFeatures()) { res[i] = (IVariable)factory.getVariable(feature.getEType().getName(), feature.getName(), getHost().eGet(feature)); ++i; } return res; }
@Override public IVariable[] getVariables() throws DebugException { Scope[] scopes = complete( getDebugTarget().debugProtocolServer.scopes(new ScopesArguments().setFrameId(stackFrame.id))).scopes; List<DSPVariable> vars = new ArrayList<>(); for (Scope scope : scopes) { DSPVariable variable = new DSPVariable(this, scope.variablesReference, scope.name, ""); vars.add(variable); } return vars.toArray(new IVariable[vars.size()]); }
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; }
public String createWatchExpression(IVariable variable) throws CoreException { Variable castVariable = (Variable) variable; String expressionText = castVariable.createWatchExpression(); if (expressionText == null) { throw new CoreException(new Status(IStatus.ERROR, ChromiumDebugPlugin.PLUGIN_ID, Messages.Variable_CANNOT_BUILD_EXPRESSION)); } return expressionText; }
private ExceptionStackFrame(EvaluateContext evaluateContext, ExceptionData exceptionData) { super(evaluateContext); this.exceptionData = exceptionData; Variable variable = Variable.forException(evaluateContext, exceptionData.getExceptionValue()); variables = new IVariable[] { variable }; }
private IVariable[] createElements() { JsArray jsArray = (JsArray) getJsValue(); return StackFrame.wrapVariables(getEvaluateContext(), jsArray.getProperties(), ARRAY_HIDDEN_PROPERTY_NAMES, // Do not show internal properties for arrays (this may be an option). null, null, getExpressionTrackerNode()); }
private IVariable[] getElements() { IVariable[] result = elementsRef.get(); if (result == null) { result = createElements(); elementsRef.compareAndSet(null, result); return elementsRef.get(); } else { return result; } }
public IVariable[] getVariables() throws DebugException { if (variables == null) { try { variables = wrapScopes(getEvaluateContext(), stackFrame.getVariableScopes(), stackFrame.getReceiverVariable(), ExpressionTracker.STACK_FRAME_FACTORY); } catch (RuntimeException e) { // We shouldn't throw RuntimeException from here, because calling // ElementContentProvider#update will forget to call update.done(). throw new DebugException(new Status(IStatus.ERROR, ChromiumDebugPlugin.PLUGIN_ID, "Failed to read variables", e)); //$NON-NLS-1$ } } return variables; }
public ErrorMessageValue(EvaluateContext evaluateContext, String message, JsValue exceptionValue) { super(evaluateContext); this.message = message; if (exceptionValue == null) { innerVariables = Value.EMPTY_VARIABLES; } else { innerVariables = new IVariable[] { Variable.forException(evaluateContext, exceptionValue) }; } }
protected IVariable[] calculateVariables() { JsObject asObject = value.asObject(); if (asObject == null) { return EMPTY_VARIABLES; } List<Variable> functionScopes = calculateFunctionScopesVariable(asObject); return StackFrame.wrapVariables(getEvaluateContext(), asObject.getProperties(), Collections.<String>emptySet(), asObject.getInternalProperties(), functionScopes, expressionNode); }
/** * {@inheritDoc} * * If selection is an instance of {@link StructuredSelection} and the first element is an * instance of {@link IVariable}, update our variables diagram view. */ public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection instanceof StructuredSelection) { Object firstElement = ((StructuredSelection) selection).getFirstElement(); if (firstElement instanceof IVariable) { IVariable var = (IVariable) firstElement; if (getViewContext() == null) { initialize(var, null, null); } else { DiagramViewManager.updateView(getViewContext(), var); } } } }
/** * Invokes a transformation that transforms the given variable into its visual representation. Does * nothing if the variable already has a visual representation associated with it in the context or * if the recursion or node count limits have already been reached. Thus, after calling this method, * the variable to be transformed might not actually have been associated with a visual * representation in the transformation context. * * <p>To find the node associated with the given variable (if any) after calling this method, use * {@link VariableTransformationContext#findAssociation(IVariable)}.</p> * * @param variable the variable to transform. * @param graph the parent graph to add the transformed representation to. * @param context the transformation context to pass to the transformation. * @throws DebugException if anything goes wrong when accessing the Eclipse debug system. */ public static final void invokeFor(final IVariable variable, final KNode graph, final VariableTransformationContext context) throws DebugException { // Check if the maximum node count or maximum transformation depth are already reached if (context.getTransformationDepth() >= DebuKVizPlugin.MAX_REFERENCES_FOLLOWED) { // TODO Perhaps create a certain kind of dummy node here? // That would make it clear that the transformation stopped there return; } // Check if the variable was already transformed if (context.findAssociation(variable) != null) { return; } // Fetch a transformation that can handle this variable's type VariableTransformation transformation = DebuKVizTransformationService.INSTANCE.transformationFor(variable); if (transformation != null) { // Invoke transformation context.increaseTransformationDepth(); transformation.transform(variable, graph, context); context.decreaseTransformationDepth(); } }
/** * 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); }
/** * Return the value of a variable as an int number. * * @param variable a variable * @return the value of the given variable interpreted as int * @throws DebugException if accessing the debug model fails */ protected final int getIntValue(IVariable variable) throws DebugException { try { return Integer.parseInt(variable.getValue().getValueString()); } catch (NumberFormatException exception) { throw new IllegalArgumentException(exception); } }
/** * Return the value of a variable as a byte number. * * @param variable a variable * @return the value of the given variable interpreted as byte * @throws DebugException if accessing the debug model fails */ protected final byte getByteValue(IVariable variable) throws DebugException { try { return Byte.parseByte(variable.getValue().getValueString()); } catch (NumberFormatException exception) { throw new IllegalArgumentException(exception); } }
/** * Return the value of a variable as a long number. * * @param variable a variable * @return the value of the given variable interpreted as long * @throws DebugException if accessing the debug model fails */ protected final long getLongValue(IVariable variable) throws DebugException { try { return Long.parseLong(variable.getValue().getValueString()); } catch (NumberFormatException exception) { throw new IllegalArgumentException(exception); } }
/** * Return the value of a variable as a float number. * * @param variable a variable * @return the value of the given variable interpreted as float * @throws DebugException if accessing the debug model fails */ protected final float getFloatValue(IVariable variable) throws DebugException { try { return Float.parseFloat(variable.getValue().getValueString()); } catch (NumberFormatException exception) { throw new IllegalArgumentException(exception); } }
/** * Return the value of a variable as a double number. * * @param variable a variable * @return the value of the given variable interpreted as double * @throws DebugException if accessing the debug model fails */ protected final double getDoubleValue(IVariable variable) throws DebugException { try { return Double.parseDouble(variable.getValue().getValueString()); } catch (NumberFormatException exception) { throw new IllegalArgumentException(exception); } }
/** * Creates a new node builder for a node that is associated with a variable. Once the node is * created, the node builder will establish the association in the transformation context. * * @param variable the variable the node will be created for. * @param graph the graph the created node will be added to. * @param context the transformation context that will be updated as the node is created. * @return the node builder. */ public static NodeBuilder forVariable(final IVariable variable, final KNode graph, final VariableTransformationContext context) { if (variable == null) { throw new NullPointerException("variable cannot be null"); } NodeBuilder builder = forPlainNode(graph, context); builder.variable = variable; return builder; }