Search in sources :

Example 1 with ValueExp

use of flash.tools.debugger.expression.ValueExp in project intellij-plugins by JetBrains.

the class DebugCLI method doWhat.

/**
	 * Print the context of a Variable
	 */
void doWhat() throws NotConnectedException {
    /* wait a bit if we are not halted */
    waitTilHalted();
    try {
        Object result = null;
        /* pull the rest of the line */
        String s = restOfLine();
        // first parse it, then attempt to evaluate the expression
        ValueExp expr = parseExpression(s);
        // make sure no assignment
        if (expr.containsAssignment())
            throw new IllegalAccessException();
        result = evalExpression(expr).value;
        /* dump the output */
        StringBuilder sb = new StringBuilder();
        if (result instanceof Variable) {
            Variable v = (Variable) result;
            // if it has a path then display it!
            if (v.isAttributeSet(VariableAttribute.IS_LOCAL))
                //$NON-NLS-1$
                s = getLocalizationManager().getLocalizedTextString("localVariable");
            else if (v.isAttributeSet(VariableAttribute.IS_ARGUMENT))
                //$NON-NLS-1$
                s = getLocalizationManager().getLocalizedTextString("functionArgumentVariable");
            else if ((v instanceof VariableFacade) && (s = ((VariableFacade) v).getPath()) != null && s.length() > 0)
                ;
            else
                //$NON-NLS-1$
                s = "_global";
            sb.append(s);
        } else
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("mustBeOnlyOneVariable"));
        out(sb.toString());
    } catch (IllegalAccessException iae) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("noSideEffectsAllowed"));
    } catch (NullPointerException npe) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("couldNotEvaluate"));
    }
}
Also used : ValueExp(flash.tools.debugger.expression.ValueExp) Variable(flash.tools.debugger.Variable)

Example 2 with ValueExp

use of flash.tools.debugger.expression.ValueExp in project intellij-plugins by JetBrains.

the class DebugCLI method doWatch.

/**
	 * Request to add a new watchpoint
	 * This may result in one of two things happening
	 * (1) a new watchpoint could be added or
	 * (2) an existing watchpoint may be modified.
	 *
	 * The watch, awatch, and rwatch commands will set a watchpoint on the
	 * given expression. The different commands control the read/write aspect
	 * of the watchpoint.
	 *
	 * awatch will trigger a break if the expression is read or written.
	 * rwatch will trigger a break if the expression is read.
	 * watch will trigger a break if the expression is written.
	 */
void doWatch(boolean read, boolean write) throws PlayerDebugException {
    try {
        if (read) {
            err("Only break-on-write watchpoints are supported.");
            return;
        }
        StringBuilder sb = new StringBuilder();
        /* pull the rest of the line */
        String s = restOfLine();
        int flags = 3;
        if (read && write)
            flags = WatchKind.READWRITE;
        else if (read)
            flags = WatchKind.READ;
        else if (write)
            flags = WatchKind.WRITE;
        // snapshot of our existing list
        Watch[] list = m_session.getWatchList();
        // We need to separate the front part the 'a.b' in 'a.b.c' 
        // of the expression to resolve it into a variable 
        // We usually get back a VariableFacade which contains
        // the context id (i.e the variable id) and the member name.
        ValueExp expr = parseExpression(s);
        VariableFacade result = (VariableFacade) (evalExpression(expr).value);
        // extract the 2 pieces and get the raw variable.
        // TODO fix this???  -mike
        int varId = result.getContext();
        String memberName = result.getName();
        Value v = m_session.getValue(varId);
        // attempt to set.
        Watch w = m_session.setWatch(v, memberName, flags);
        if (w == null) {
            // failed
            Map<String, Object> args = new HashMap<String, Object>();
            //$NON-NLS-1$
            args.put("expression", s);
            //$NON-NLS-1$
            err(getLocalizationManager().getLocalizedTextString("watchpointCouldNotBeSet", args));
        } else {
            // if modified then lists are same length
            // otherwise 1 will be added
            Watch[] newList = m_session.getWatchList();
            if (newList.length == list.length) {
                // modified, lets locate the one that changed
                // and reset it
                int at = missingWatchpointIndexOf(newList);
                WatchAction a = null;
                try {
                    a = watchpointAt(at);
                } catch (ArrayIndexOutOfBoundsException aio) {
                    // this is pretty bad it means the player thinks we have a watchpoint
                    // but we don't have a record of it.  So let's create a new one
                    // and hope that we are now in sync with the player.
                    a = new WatchAction(w);
                }
                // modify our view of the watchpoint
                int id = a.getId();
                a.resetWatch(w);
                Map<String, Object> args = new HashMap<String, Object>();
                //$NON-NLS-1$
                args.put("watchpointNumber", Integer.toString(id));
                //$NON-NLS-1$
                args.put("expression", s);
                //$NON-NLS-1$
                args.put("watchpointMode", getWatchpointModeString(a.getKind()));
                //$NON-NLS-1$
                sb.append(getLocalizationManager().getLocalizedTextString("changedWatchpointMode", args));
            } else {
                // newly added
                WatchAction a = new WatchAction(w);
                watchpointAdd(a);
                int which = a.getId();
                Map<String, Object> args = new HashMap<String, Object>();
                //$NON-NLS-1$
                args.put("watchpointNumber", Integer.toString(which));
                //$NON-NLS-1$
                args.put("expression", s);
                //$NON-NLS-1$
                sb.append(getLocalizationManager().getLocalizedTextString("createdWatchpoint", args));
            }
            out(sb.toString());
        }
    } catch (ArrayIndexOutOfBoundsException aio) {
        // We should really do some cleanup after this exception
        // since it most likely means we can't find the watchpoint
        // that was just modified, therefore our watchlists are
        // out of sync with those of the API.
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("badWatchpointNumber"));
    } catch (NullPointerException npe) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("couldNotEvaluate"));
    } catch (ClassCastException cce) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("couldNotResolveExpression"));
    }
}
Also used : ValueExp(flash.tools.debugger.expression.ValueExp) HashMap(java.util.HashMap) Watch(flash.tools.debugger.Watch) Value(flash.tools.debugger.Value)

Example 3 with ValueExp

use of flash.tools.debugger.expression.ValueExp in project intellij-plugins by JetBrains.

the class DebugCLI method doMcTree.

/**
	 * Specialized dump of the contents of a movie clip tree, dumping
	 * all the _target properties of all MCs
	 * @throws NoResponseException 
	 * @throws NotSuspendedException 
	 */
void doMcTree() throws NotConnectedException, NotSuspendedException, NoResponseException {
    /* wait a bit if we are not halted */
    waitTilHalted();
    try {
        // our variable reference
        String var = nextToken();
        //$NON-NLS-1$
        String member = "_target";
        boolean printPath = false;
        Object result = null;
        String name = null;
        // did the user specify a member name
        if (hasMoreTokens()) {
            member = nextToken();
            // did they specify some other options
            while (hasMoreTokens()) {
                String option = nextToken();
                if (//$NON-NLS-1$
                option.equalsIgnoreCase("fullpath"))
                    printPath = true;
            }
        }
        // first parse it, then attempt to evaluate the expression
        ValueExp expr = parseExpression(var);
        result = evalExpression(expr).value;
        StringBuilder sb = new StringBuilder();
        if (result instanceof Variable) {
            name = ((Variable) result).getName();
            result = ((Variable) result).getValue();
        }
        if (result instanceof Value) {
            ArrayList<Object> e = new ArrayList<Object>();
            dumpTree(new HashMap<Object, String>(), e, name, (Value) result, member);
            // now sort according to our criteria
            treeResults(sb, e, member, printPath);
        } else
            throw new NoSuchVariableException(result);
        out(sb.toString());
    } catch (NoSuchVariableException nsv) {
        Map<String, Object> args = new HashMap<String, Object>();
        //$NON-NLS-1$
        args.put("variable", nsv.getMessage());
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("variableUnknown", args));
    } catch (NullPointerException npe) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("couldNotEvaluate"));
    }
}
Also used : ValueExp(flash.tools.debugger.expression.ValueExp) Variable(flash.tools.debugger.Variable) NoSuchVariableException(flash.tools.debugger.expression.NoSuchVariableException) ArrayList(java.util.ArrayList) Value(flash.tools.debugger.Value) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ValueExp

use of flash.tools.debugger.expression.ValueExp in project intellij-plugins by JetBrains.

the class DebugCLI method doSet.

void doSet() throws NotConnectedException {
    //		waitTilHalted();
    try {
        Object result = null;
        ValueExp exp = null;
        if (!hasMoreTokens())
            //$NON-NLS-1$
            err(getLocalizationManager().getLocalizedTextString("setCommand"));
        else {
            // pull the expression
            String s = restOfLine();
            // parse and eval which causes the assignment to occur...
            if ((exp = parseExpression(s)) == null)
                // failed parse
                ;
            else // make sure contains assignment
            if (!exp.containsInstanceOf(AssignmentExp.class))
                //$NON-NLS-1$
                throw new IllegalAccessException("=");
            else if ((result = evalExpression(exp)) == null)
                // eval failed
                ;
        }
        // done so dump a result if we have a negative one
        StringBuffer sb = new StringBuffer();
        if (result == null)
            // error already issued
            ;
        else if (result instanceof Boolean && !((Boolean) result).booleanValue())
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("assignmentFailed"));
        if (exp != null && sb.length() > 0)
            out(sb.toString());
    } catch (IllegalAccessException iae) {
        Map args = new HashMap();
        //$NON-NLS-1$
        args.put("operator", iae.getMessage());
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("missingOperator", args));
    } catch (NullPointerException npe) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("couldNotEvaluate"));
    }
}
Also used : ValueExp(flash.tools.debugger.expression.ValueExp) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with ValueExp

use of flash.tools.debugger.expression.ValueExp in project intellij-plugins by JetBrains.

the class DebugCLI method doDisplay.

/**
	 * Display command
	 */
void doDisplay() {
    try {
        if (!hasMoreTokens())
            doInfoDisplay();
        else {
            // followed by an expression (i.e. a line we just pull in)
            String s = restOfLine();
            // first parse it, then attempt to evaluate the expression
            ValueExp expr = parseExpression(s);
            // make sure no assignment
            if (expr.containsAssignment())
                throw new IllegalAccessException();
            // it worked so create a new DisplayAction and then add it in
            DisplayAction b = new DisplayAction(expr, s);
            b.setEnabled(true);
            displayAdd(b);
        }
    } catch (IllegalAccessException iae) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("noSideEffectsAllowed"));
    } catch (NullPointerException npe) {
    // already handled by parseExpression
    }
}
Also used : ValueExp(flash.tools.debugger.expression.ValueExp)

Aggregations

ValueExp (flash.tools.debugger.expression.ValueExp)8 HashMap (java.util.HashMap)5 Map (java.util.Map)4 Variable (flash.tools.debugger.Variable)3 Value (flash.tools.debugger.Value)2 NoSuchVariableException (flash.tools.debugger.expression.NoSuchVariableException)2 Watch (flash.tools.debugger.Watch)1 EvaluationResult (flex.tools.debugger.cli.ExpressionCache.EvaluationResult)1 ArrayList (java.util.ArrayList)1