Search in sources :

Example 1 with XBreakpointHandler

use of com.intellij.xdebugger.breakpoints.XBreakpointHandler in project intellij-plugins by JetBrains.

the class FlexDebugProcess method processOneCommandLoop.

private void processOneCommandLoop() throws IOException, InterruptedException {
    assert Thread.currentThread() == myDebuggerManagerThread;
    final DebuggerCommand command = postCommand();
    if (command == null)
        return;
    boolean explicitlyContinueRead = false;
    do {
        final CommandOutputProcessingType outputProcessingType = command.getOutputProcessingMode();
        if (outputProcessingType == CommandOutputProcessingType.NO_PROCESSING || (outputProcessingType == CommandOutputProcessingType.DEFAULT_PROCESSING && !reader.hasSomeDataPending())) {
            return;
        }
        if (myCheckForUnexpectedStartupStop && !(command instanceof DumpOutputCommand)) {
            myCheckForUnexpectedStartupStop = false;
        }
        @NonNls String commandOutput = null;
        try {
            commandOutput = command.read(this);
        } catch (IOException e) {
            if (!(command instanceof QuitCommand)) {
                throw e;
            }
        }
        if (command instanceof QuitCommand) {
            // request to finish
            Thread.currentThread().interrupt();
        }
        if (commandOutput == null)
            break;
        if (commandOutput.contains("Player session terminated") && !(command instanceof SuspendResumeDebuggerCommand)) {
            handleProbablyUnexpectedStop(commandOutput);
            break;
        }
        commandOutput = commandOutput.trim();
        log(commandOutput);
        if (outputProcessingType == CommandOutputProcessingType.SPECIAL_PROCESSING) {
            log("Processed by " + command);
            if (command.onTextAvailable(commandOutput) == CommandOutputProcessingMode.DONE)
                break;
            explicitlyContinueRead = true;
            continue;
        }
        ResponseLineIterator iterator = new ResponseLineIterator(commandOutput);
        boolean toInsertContinue = false;
        boolean encounteredNonsuspendableBreakpoint = false;
        int index;
        while (iterator.hasNext()) {
            final String line = iterator.next();
            if (line.startsWith("Active worker has changed to worker ")) {
                try {
                    final String workerText = line.substring("Active worker has changed to worker ".length());
                    if ("Main Thread".equals(workerText)) {
                        myCurrentWorker = 0;
                    } else {
                        myCurrentWorker = Integer.parseInt(workerText);
                    }
                } catch (NumberFormatException e) {
                    log("Unexpected worker number");
                }
            } else if (line.contains("Additional ActionScript code has been loaded")) {
                if (!suspended)
                    reader.readLine(false);
                myKnownFilesInfo.setUpToDate(false);
            } else if ((index = line.indexOf(BREAKPOINT_MARKER)) != -1 && !line.contains(" created")) {
                // Breakpoint 1, aaa() at A.mxml:14
                try {
                    final int from = index + BREAKPOINT_MARKER.length();
                    // Breakpoint 1, aaa() at A.mxml:14
                    // Breakpoint 2: file ConfigurationService.as
                    // Breakpoint 3 at 0xFFF
                    int endOfBreakpointIndexPosition = line.indexOf(',', from);
                    final int colonIndex = line.indexOf(':', from);
                    final int spaceIndex = line.indexOf(' ', from);
                    if (endOfBreakpointIndexPosition != -1) {
                        if (colonIndex != -1) {
                            endOfBreakpointIndexPosition = Math.min(colonIndex, endOfBreakpointIndexPosition);
                        }
                        if (spaceIndex != -1) {
                            endOfBreakpointIndexPosition = Math.min(spaceIndex, endOfBreakpointIndexPosition);
                        }
                        index = Integer.parseInt(line.substring(from, endOfBreakpointIndexPosition));
                        final XLineBreakpoint<XBreakpointProperties> breakpoint = myBreakpointsHandler.getBreakpointByIndex(index);
                        if (breakpoint != null) {
                            FlexStackFrame frame = new FlexStackFrame(this, breakpoint.getSourcePosition());
                            boolean suspend = false;
                            if (evaluateCondition(breakpoint.getConditionExpression(), frame)) {
                                String message = evaluateMessage(breakpoint.getLogExpressionObject(), frame);
                                suspend = getSession().breakpointReached(breakpoint, message, new FlexSuspendContext(frame));
                            }
                            if (!suspend) {
                                encounteredNonsuspendableBreakpoint = true;
                                toInsertContinue = true;
                            }
                        } else {
                            // run to cursor break point
                            insertCommand(myBreakpointsHandler.new RemoveBreakpointCommand(index, breakpoint));
                        }
                    }
                } catch (NumberFormatException ex) {
                    log(ex);
                }
            } else if (line.length() > 0 && Character.isDigit(line.charAt(0))) {
                // we are on new location: e.g. " 119           trace('\x30 \123')"
                if (!encounteredNonsuspendableBreakpoint)
                    insertCommand(new DumpSourceLocationCommand(this));
            } else if (handleStdResponse(line, iterator)) {
            } else if (line.startsWith(RESOLVED_BREAKPOINT_MARKER)) {
                // TODO: move to break point handler
                // Resolved breakpoint 1 to aaa() at A.mxml:14
                final String breakPointNumber = line.substring(RESOLVED_BREAKPOINT_MARKER.length(), line.indexOf(' ', RESOLVED_BREAKPOINT_MARKER.length()));
                myBreakpointsHandler.updateBreakpointStatusToVerified(breakPointNumber);
            } else if (line.startsWith(ATTEMPTING_TO_RESOLVE_BREAKPOINT_MARKER)) {
                // TODO: move to break point handler
                int breakpointId = Integer.parseInt(line.substring(ATTEMPTING_TO_RESOLVE_BREAKPOINT_MARKER.length(), line.indexOf(',')));
                final XLineBreakpoint<XBreakpointProperties> breakpoint = myBreakpointsHandler.getBreakpointByIndex(breakpointId);
                if (iterator.hasNext() && iterator.getNext().contains("no executable code")) {
                    iterator.next();
                    myBreakpointsHandler.updateBreakpointStatusToInvalid(breakpoint);
                    toInsertContinue = true;
                } else if (iterator.hasNext() && iterator.getNext().contains(AMBIGUOUS_MATCHING_FILE_NAMES)) {
                    iterator.next();
                    iterator.next();
                    while (iterator.hasNext() && iterator.getNext().contains("#")) {
                        iterator.next();
                    }
                    if (getFileId(breakpoint.getSourcePosition().getFile().getPath()) != null) {
                        final XBreakpointHandler handler = getBreakpointHandlers()[0];
                        handler.unregisterBreakpoint(breakpoint, false);
                        handler.registerBreakpoint(breakpoint);
                    }
                    toInsertContinue = true;
                }
            } else if (line.startsWith("Set additional breakpoints")) {
                //Set additional breakpoints as desired, and then type 'continue'.
                // TODO: move to break point handler
                toInsertContinue = true;
            } else if (line.contains("Execution halted")) {
                if (!getSession().isPaused()) {
                    getSession().pause();
                }
            }
        }
        if (toInsertContinue)
            insertCommand(new ContinueCommand());
    } while (explicitlyContinueRead || reader.hasSomeDataPending());
}
Also used : NonNls(org.jetbrains.annotations.NonNls) IOException(java.io.IOException) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XBreakpointProperties(com.intellij.xdebugger.breakpoints.XBreakpointProperties) XBreakpointHandler(com.intellij.xdebugger.breakpoints.XBreakpointHandler)

Aggregations

XBreakpointHandler (com.intellij.xdebugger.breakpoints.XBreakpointHandler)1 XBreakpointProperties (com.intellij.xdebugger.breakpoints.XBreakpointProperties)1 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)1 IOException (java.io.IOException)1 NonNls (org.jetbrains.annotations.NonNls)1