Package org.openquark.cal.internal.runtime

Examples of org.openquark.cal.internal.runtime.ExecutionContextImpl$DebugController


     * Show the state of the suspended CAL program.
     * Currently this displays the function name and the
     * names and values of any arguments.
     */
    private void command_showSuspensionState () {
        ExecutionContextImpl ec = getExecutionContext();
        Map<Thread, SuspensionState> suspensions = ec.getThreadSuspensions();
        if (suspensions.isEmpty()) {
            logInfo("There are no currently suspended threads.");
            return;
        }
       
View Full Code Here


   
    private void command_terminateExecution (String info) {
        // Set the quit flag for the CAL execution thread and then
        // let it resume execution. This lets the CAL program terminate
        // gracefully.
        ExecutionContextImpl ec = getExecutionContext();
       
        // Remember the state of tracing and then turn it off.
        boolean traceOn = ec.isTracingEnabled();
        ec.setTracingEnabled(false);
       
        Set<String> breakpoints = ec.getBreakpoints();
        ec.clearBreakpoints();      
       
        Set<String> tracedFunctions = ec.getTracedFunctions();
       
        // We want to go into a loop here in case
        // we hit another breakpoint before the machine
        // notices that a quit has been requested.
        while (ec.hasSuspendedThreads()) {
            ec.setStepping(false);
            ICE.this.runThread.requestQuit();
            getDebugController().setShouldBlockUI(true);
            ec.resumeAll();
            getDebugController().blockUntilCompletionOrInterruption();
        }
       
        ec.setTracingEnabled(traceOn);
        ec.setTracedFunctions(tracedFunctions)
        ec.setBreakpoints(breakpoints);            
    }
View Full Code Here

     * org.openquark.cal.machine.debug_capable is defined.
     * @param info
     */
    private void command_step (String info) {

        ExecutionContextImpl ec = getExecutionContext();

        String expression = info.trim();
        if (expression.length() > 0) {
            // We want to start execution of the expression the step flag set.
            if (ec.hasSuspendedThreads()) {
                logInfo("There is a CAL program currently suspended.");
                logInfo("Terminate the suspended program with :te before stepping into a new program.");
            } else {
                ec.setStepAllThreads(true);
                ec.setStepping(true);
                command_runCode(info);
            }
        } else {
            // There is nothing following 'step'.  If we
            // are suspended tell the execution context to step
            // and then resume execution.
            if (ec.hasSuspendedThreads()) {
                ec.setStepAllThreads(false);
                ec.setStepping(true);
                command_resumeCurrentThread(true);
            } else {
                logInfo("There is no CAL program currently suspended.");
            }
        }
View Full Code Here

    /**
     * Show different pieces of information about a suspended CAL execution.
     * @param info
     */
    private void command_show (String info) {
        ExecutionContextImpl ec = getExecutionContext();
        if (!ec.hasSuspendedThreads()) {
            logInfo("There is no CAL program currently suspended.");
            return;
        }

        final Map<Thread, SuspensionState> suspendedThreads = ec.getThreadSuspensions();
        final Thread currentSuspendedThread = getDebugController().getCurrentSuspendedThread();
        if (!suspendedThreads.containsKey(currentSuspendedThread)) {
            iceLogger.log(Level.INFO, "The current thread is no longer suspended. Change to another thread.");
            return;
        }
View Full Code Here

    /**
     * Manage breakpoints in the CAL program.
     * @param info
     */
    private void command_breakpoint (String info) {
        ExecutionContextImpl ec = getExecutionContext();
       
        // Get first word from info.
        StringTokenizer tokenizer = new StringTokenizer(info);

        try {
            String firstWord = tokenizer.nextToken();
           
            // :bp show
            // Display the set breakpoints.
            if (firstWord.toLowerCase().equals("show")) {
                Set<String> bps = ec.getBreakpoints();
                if (bps.isEmpty()) {
                    logInfo("No breakpoints currently set.");
                    return;
                }
                logInfo("Breakpoints: ");
                for (final String name : bps) {
                    logInfo("    " + name);
                }
                return;
            } else
            if (firstWord.toLowerCase().equals("clear")) {
                ec.clearBreakpoints();
                logInfo("All breakpoints removed.");
                return;
            }
           
            String functionName = firstWord;
           
            // Determine if function name is a valid CAL function or data constructor.
            try {
                QualifiedName qn = resolveQualifiedNameInProgram(QualifiedName.makeFromCompoundName(functionName));
                if (qn == null) {
                    return;
                }
                functionName = qn.getQualifiedName();
               
                ModuleTypeInfo mt = getWorkspaceManager().getModuleTypeInfo(qn.getModuleName());
               
                DataConstructor dc = mt.getDataConstructor(qn.getUnqualifiedName());
                if (dc != null) {
                    if (dc.getArity() == 0) {
                        logInfo("Cannot set a breakpoint on a zero arity data constructor.");
                        return;
                    }
                } else 
                if (mt.getFunction(qn.getUnqualifiedName()) == null) {
                    logInfo(qn + " is not a valid function name.");
                    return;
                }
                   
            } catch (IllegalArgumentException e) {
                logInfo(functionName + " is not a valid compound name.");
                return;
            }
           
            // functionName is valid so we want to toggle its breakpoint.
            Set<String> breakpoints = new HashSet<String>(ec.getBreakpoints());
            if (breakpoints.contains(functionName)) {
                breakpoints.remove(functionName);
                ec.setBreakpoints(breakpoints);
                logInfo("Breakpoint disabled for " + functionName);
            } else {
                breakpoints.add(functionName);               
                ec.setBreakpoints(breakpoints);
                logInfo("Breakpoint enabled for " + functionName);
            }
               
           
        } catch (NoSuchElementException e) {
View Full Code Here

     * Note: for these changes to have effect the system property
     * org.openquark.cal.machine.debug_capable must be defined.
     * @param info - the content of the command line after the command text is stripped.
     */
    private void command_trace (String info) {
        ExecutionContextImpl ec = getExecutionContext();
       
        // Get first word from info.
        StringTokenizer tokenizer = new StringTokenizer(info);

        try {
            String firstWordRaw = tokenizer.nextToken();
            String firstWord = firstWordRaw.toLowerCase();
           
            // :trace on
            if (firstWord.equals("on")) {
                ec.setTracingEnabled(true);
                logInfo("General function tracing enabled.");
            } else
            // :trace off
            if (firstWord.equals("off")) {
                ec.setTracingEnabled(false);
                logInfo("General function tracing disabled.");
            } else
            // :trace threadname on/off
            if (firstWord.equals("threadname")) {
                String tf = tokenizer.nextToken().toLowerCase();
                if (tf.equals("on")) {
                    ec.setTraceShowsThreadName(true);
                    logInfo("Tracing of thread name enabled.");
                }else if (tf.equals("off")) {
                    ec.setTraceShowsThreadName(false);
                    logInfo("Tracing of thread name disabled.");
                }else {
                    logInfo("Unrecognized trace command  :trace " + info);
                }
            } else
            // :trace arguments on/off
            if (firstWord.equals("arguments")) {
                String tf = tokenizer.nextToken().toLowerCase();
                if (tf.equals("on")) {
                    ec.setTraceShowsFunctionArgs(true);
                    logInfo("Tracing of arguments enabled.");
                }else if (tf.equals("off")) {
                    ec.setTraceShowsFunctionArgs(false);
                    logInfo("Tracing of arguments disabled.");
                }else {
                    logInfo("Unrecognized trace command  :trace " + info);
                }
            } else
            if (firstWord.equals("clear")) {
                ec.clearTracedFunctions();
                logInfo("All traced functions removed.");
            } else {
                // :trace Module.function
                String functionName = firstWordRaw;
                try {
                    // Check that the function name is valid.
                    QualifiedName qn = resolveQualifiedNameInProgram(QualifiedName.makeFromCompoundName(functionName));
                    if (qn == null) {
                        return;
                    }
                    functionName = qn.getQualifiedName();
                   
                    try {
                        if(getWorkspaceManager().getMachineFunction(qn) == null) {
                            logInfo(qn.getQualifiedName() + " is not a valid function.");
                            return;
                        }
                    } catch (ProgramException e) {
                        logInfo(qn.getQualifiedName() + " is not a valid function.");
                        return;
                    }
                } catch (IllegalArgumentException e) {
                    logInfo(functionName + " is not a valid compound name.");
                    return;
                }
               
                // The function name is valid so we want to toggle the trace state for it.              
                Set<String> tracedFunctions = new HashSet<String>(ec.getTracedFunctions());
                if (!tracedFunctions.contains(functionName)) {                   
                    tracedFunctions.add(functionName);                  
                    ec.setTracedFunctions(tracedFunctions);
                    logInfo("Tracing enabled for " + functionName);
                }else {
                    tracedFunctions.remove(functionName);
                    ec.setTracedFunctions(tracedFunctions);
                    logInfo("Tracing disabled for " + functionName);
                }
            }           
           
        } catch (NoSuchElementException e) {
View Full Code Here

        }
       
       
        // If we don't have the runThread yet we need to create it.
        makeRunThread();
        ExecutionContextImpl ec = runThread.getExecutionContext();
       
        logInfo("");
        logInfo("Current trace settings:");
        logInfo("overall tracing is " + (ec.isTracingEnabled() ? "Enabled" : "Disabled"));
        logInfo("trace shows function args - " + ec.traceShowsFunctionArgs());
        logInfo("trace shows thread name   - " + ec.traceShowsThreadName());

        Set<String> tracedFunctions = ec.getTracedFunctions();
        logInfo(tracedFunctions.size() + " functions have tracing enabled.");
        for (final String tracedFunction : tracedFunctions) {
            logInfo("    " + tracedFunction);
        }
       
        List<Pattern> traceFilters = ec.getTraceFilters();
        logInfo(traceFilters.size() + " trace filters are set.");
        for (int i = 0, n = traceFilters.size(); i < n; ++i) {
            logInfo("    " + (i+1) + " :   " + traceFilters.get(i).toString());
        }
    }
View Full Code Here

        addCommand(new ICECommand(new String[] { "re" }, true, true,
                CommandType.DEBUG, new String[] { ":re" },
                new String[] { "Resume execution of suspended CAL program." }) {
            @Override
            protected void performCommand(String info) {
                ExecutionContextImpl ec = ICE.this.getExecutionContext();
                if (ec.hasSuspendedThreads()) {
                    ec.setStepping(false);
                    command_resumeExecution();
                } else {
                    iceLogger.log(Level.INFO, "There is no CAL program currently suspended.");
                }
            }
        });
        addCommand(new ICECommand(new String[] { "ret" }, true, true,
                CommandType.DEBUG, new String[] { ":ret" },
                new String[] { "Resume execution of the current suspended thread." }) {
            @Override
            protected void performCommand(String info) {
                ExecutionContextImpl ec = ICE.this.getExecutionContext();
                if (ec.hasSuspendedThreads()) {
                    ec.setStepping(false);
                    command_resumeCurrentThread(false);
                } else {
                    iceLogger.log(Level.INFO, "There is no CAL program currently suspended.");
                }
            }
        });
        addCommand(new ICECommand(new String[] { "sus", "suspend" }, true, true,
                CommandType.DEBUG, new String[] { ":sus[pend]" },
                new String[] { "Suspend all threads in the executing CAL program." }) {
            @Override
            protected void performCommand(String info) {
                if (runThread != null) {
                    runThread.requestSuspend();
                }
            }
        });
        addCommand(new ICECommand(new String[] { "threads" }, true, true,
                CommandType.DEBUG, new String[] { ":threads" },
                new String[] { "Show the current suspended threads." }) {
            @Override
            protected void performCommand(String info) {
                ExecutionContextImpl ec = ICE.this.getExecutionContext();
                if (ec.hasSuspendedThreads()) {
                    command_showSuspendedThreads();
                } else {
                    iceLogger.log(Level.INFO, "There is no CAL program currently suspended.");
                }
            }
        });
        addCommand(new ICECommand(new String[] { "thread" }, true, true,
                CommandType.DEBUG, new String[] { ":thread <thread id>" },
                new String[] { "Set the current suspended thread." }) {
            @Override
            protected void performCommand(String info) {
                ExecutionContextImpl ec = ICE.this.getExecutionContext();
                if (ec.hasSuspendedThreads()) {
                    command_setSuspendedThread(info);
                } else {
                    iceLogger.log(Level.INFO, "There is no CAL program currently suspended.");
                }
            }
        });
        addCommand(new ICECommand(new String[] { "te" }, true, true,
                CommandType.DEBUG, new String[] { ":te" },
                new String[] { "Terminate execution of suspended CAL program." }) {
            @Override
            protected void performCommand(String info) {
                ExecutionContextImpl ec = ICE.this.getExecutionContext();
                if (ec.hasSuspendedThreads()) {
                    command_terminateExecution(info);
                    ec.setStepping(false);
                } else {
                    iceLogger.log(Level.INFO, "There is no CAL program currently suspended.");
                }
            }
        });
View Full Code Here

            try {
                if (nextCommand.length() == 0) {
                   
                    // Emit the prompt
                    outputStream.println(" ");
                    ExecutionContextImpl ec = getExecutionContext();
                    Map<Thread, SuspensionState> suspensions = ec.getThreadSuspensions();
                   
                    if (!suspensions.isEmpty()) {
                        Thread currentThread = getDebugController().getCurrentSuspendedThread();
                        SuspensionState suspension = suspensions.get(currentThread);
                        if (suspension == null) {
View Full Code Here

       
        return runThread.getError() == null;
    }
   
    private boolean command_resumeExecution () {
        ExecutionContextImpl ec = getExecutionContext();
       
        // If we're not suspended we can't resume.
        if (!ec.hasSuspendedThreads()) {
            iceLogger.log(Level.INFO, "There is no CAL program currently suspended.");
            return true;
        }
       
        iceLogger.log(Level.INFO, "Resuming execution of: " + lastCode);
       
        // Start an interrupt monitor.  This checks the input stream and sets
        // the runThread halt flag if any input is detected while the CAL
        // program is executing.
        InterruptMonitor im = new InterruptMonitor (runThread);
        im.start();

        // Tell the execution context that it is time to resume.
        getDebugController().setShouldBlockUI(true);
        ec.resumeAll();
        getDebugController().blockUntilCompletionOrInterruption();
       
        // Shut down the interrupt monitor.
        im.end();
        im.interrupt();
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.runtime.ExecutionContextImpl$DebugController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.