Search in sources :

Example 21 with SourceFile

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

the class DebugCLI method listFilesMatching.

void listFilesMatching(StringBuilder sb, String match) {
    SourceFile[] sourceFiles = m_fileInfo.getFiles(match);
    for (int j = 0; j < sourceFiles.length; j++) {
        SourceFile sourceFile = sourceFiles[j];
        sb.append(sourceFile.getName());
        sb.append('#');
        sb.append(sourceFile.getId());
        sb.append(m_newline);
    }
}
Also used : SourceFile(flash.tools.debugger.SourceFile)

Example 22 with SourceFile

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

the class DebugCLI method setInitialSourceFile.

/**
	 * When we begin a debugging session, it would be nice if the default file
	 * for the "list" command etc. was the user's main MXML application file.
	 * There is no good way to really figure out what that file is, but we can
	 * certainly take a guess.
	 */
private void setInitialSourceFile() {
    int largestAuthoredId = -1;
    SourceFile[] files = m_fileInfo.getFileList();
    for (int i = 0; i < files.length; ++i) {
        SourceFile sf = files[i];
        if (sf.getId() > largestAuthoredId && getFileType(sf) == AUTHORED_FILE)
            largestAuthoredId = sf.getId();
    }
    if (largestAuthoredId != -1)
        setListingPosition(largestAuthoredId, 1);
}
Also used : SourceFile(flash.tools.debugger.SourceFile)

Example 23 with SourceFile

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

the class DebugCLI method parseFunctionName.

/**
	 * Parse a partial function name
	 * @param module the FIRST module to search; but we also search all the others if 'onlyThisModule' is false
	 * @return two ints: first is the module, and second is the line
	 */
private int[] parseFunctionName(int module, String partialFunctionName, boolean onlyThisModule) throws NoMatchException, AmbiguousException {
    // wait a bit before we try this to give the background thread time to complete
    try {
        waitForMetaData();
    } catch (InProgressException ipe) {
    }
    SourceFile m = m_fileInfo.getFile(module);
    // each member is a ModuleFunctionPair
    ArrayList<ModuleFunctionPair> functionNames = new ArrayList<ModuleFunctionPair>();
    appendFunctionNamesMatching(functionNames, m, partialFunctionName);
    if (functionNames.size() == 0) {
        if (!onlyThisModule) {
            // not found in the specified module; search all the other modules
            Iterator fileIter = m_fileInfo.getAllFiles();
            while (fileIter.hasNext()) {
                SourceFile nextFile = (SourceFile) ((Map.Entry) fileIter.next()).getValue();
                if (// skip the one file we searched at the beginning
                nextFile != m) {
                    appendFunctionNamesMatching(functionNames, nextFile, partialFunctionName);
                }
            }
        }
        if (functionNames.size() == 0) {
            Map<String, Object> args = new HashMap<String, Object>();
            //$NON-NLS-1$
            args.put("name", partialFunctionName);
            //$NON-NLS-1$
            throw new NoMatchException(getLocalizationManager().getLocalizedTextString("noFunctionWithSpecifiedName", args));
        }
    }
    if (functionNames.size() > 1) {
        ModuleFunctionPair[] functionNameArray = functionNames.toArray(new ModuleFunctionPair[functionNames.size()]);
        Arrays.sort(functionNameArray);
        //$NON-NLS-1$
        String s = getLocalizationManager().getLocalizedTextString("ambiguousMatchingFunctionNames") + m_newline;
        Map<String, Object> args = new HashMap<String, Object>();
        for (int i = 0; i < functionNameArray.length; i++) {
            String moduleName = m_fileInfo.getFile(functionNameArray[i].moduleId).getName();
            String functionName = functionNameArray[i].functionName;
            //$NON-NLS-1$
            args.put("functionName", functionName);
            //$NON-NLS-1$ //$NON-NLS-2$
            args.put("filename", moduleName + "#" + functionNameArray[i].moduleId);
            //$NON-NLS-1$ //$NON-NLS-2$
            s += " " + getLocalizationManager().getLocalizedTextString("functionInFile", args);
            if (i < functionNameArray.length - 1)
                s += m_newline;
        }
        throw new AmbiguousException(s);
    }
    ModuleFunctionPair pair = functionNames.get(0);
    module = pair.moduleId;
    m = m_fileInfo.getFile(module);
    int line = m.getLineForFunctionName(m_session, pair.functionName);
    return new int[] { module, line };
}
Also used : InProgressException(flash.tools.debugger.InProgressException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SourceFile(flash.tools.debugger.SourceFile) Map(java.util.Map) HashMap(java.util.HashMap)

Example 24 with SourceFile

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

the class DebugCLI method dumpBreakLine.

void dumpBreakLine(boolean postStep, StringBuffer sb) throws NotConnectedException {
    int bp = -1;
    //$NON-NLS-1$
    String name = getLocalizationManager().getLocalizedTextString("unknownFilename");
    int line = -1;
    // clear our current frame display
    propertyPut(DISPLAY_FRAME_NUMBER, 0);
    /* dump a context line to the console */
    Location l = getCurrentLocation();
    // figure out why we stopped
    int reason = SuspendReason.Unknown;
    try {
        reason = m_session.suspendReason();
    } catch (PlayerDebugException pde) {
    }
    // then see if it because of a swfloaded event
    if (reason == SuspendReason.ScriptLoaded) {
        // since the player takes a long time to provide swf/swd, try 80 * 250ms = ~20s
        if (propertyGet(METADATA_ATTEMPTS) > 0)
            try {
                waitForMetaData(80);
            } catch (InProgressException ipe) {
            }
        m_fileInfo.setDirty();
        processEvents();
        propagateBreakpoints();
        //$NON-NLS-1$
        sb.append(getLocalizationManager().getLocalizedTextString("additionalCodeLoaded"));
        sb.append(m_newline);
        if (resolveBreakpoints(sb))
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("setAdditionalBreakpoints") + m_newline);
        else
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("fixBreakpoints") + m_newline);
    } else if (l == null || l.getFile() == null) {
        // no idea where we are ?!?
        propertyPut(LAST_FRAME_DEPTH, 0);
        //$NON-NLS-1$
        sb.append(getLocalizationManager().getLocalizedTextString("executionHalted"));
        sb.append(' ');
        /** disable this line (and enable the one after) if implementation Extensions are not provided */
        appendBreakInfo(sb);
    //sb.append("unknown location");
    } else {
        SourceFile file = l.getFile();
        name = file.getName();
        line = l.getLine();
        String funcName = file.getFunctionNameForLine(m_session, line);
        // where were we last time
        int lastModule = propertyGet(LIST_MODULE);
        int lastDepth = propertyGet(LAST_FRAME_DEPTH);
        int thisModule = file.getId();
        // triggered via getCurrentLocation()
        int thisDepth = propertyGet(CURRENT_FRAME_DEPTH);
        // mark where we stopped
        propertyPut(LAST_FRAME_DEPTH, thisDepth);
        // if we have changed our context or we are not spitting out source then dump our location
        if (!postStep || lastModule != thisModule || lastDepth != thisDepth) {
            // is it a fault?
            String reasonForHalting;
            if (reason == SuspendReason.Fault || reason == SuspendReason.StopRequest) {
                StringBuffer s = new StringBuffer();
                appendReason(s, reason);
                reasonForHalting = s.toString();
            } else // if its a breakpoint add that information
            if ((bp = enabledBreakpointIndexOf(l)) > -1) {
                Map args = new HashMap();
                //$NON-NLS-1$
                args.put("breakpointNumber", Integer.toString(breakpointAt(bp).getId()));
                //$NON-NLS-1$
                reasonForHalting = getLocalizationManager().getLocalizedTextString("hitBreakpoint", args);
            } else {
                //$NON-NLS-1$
                reasonForHalting = getLocalizationManager().getLocalizedTextString("executionHalted");
            }
            Map args = new HashMap();
            //$NON-NLS-1$
            args.put("reasonForHalting", reasonForHalting);
            //$NON-NLS-1$
            args.put("fileAndLine", name + ':' + line);
            String formatString;
            if (funcName != null) {
                //$NON-NLS-1$
                args.put("functionName", funcName);
                //$NON-NLS-1$
                formatString = "haltedInFunction";
            } else {
                //$NON-NLS-1$
                formatString = "haltedInFile";
            }
            sb.append(getLocalizationManager().getLocalizedTextString(formatString, args));
            if (!m_fullnameOption)
                sb.append(m_newline);
        }
        // set current listing poistion and emit emacs trigger
        setListingPosition(thisModule, line);
        // dump our source line if not in emacs mode
        if (!m_fullnameOption)
            appendSource(sb, file.getId(), line, file.getLine(line), false);
    }
}
Also used : InProgressException(flash.tools.debugger.InProgressException) HashMap(java.util.HashMap) PlayerDebugException(flash.tools.debugger.PlayerDebugException) SourceFile(flash.tools.debugger.SourceFile) Map(java.util.Map) HashMap(java.util.HashMap) Location(flash.tools.debugger.Location)

Example 25 with SourceFile

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

the class DebugCLI method doInfoBreak.

void doInfoBreak() throws NotConnectedException {
    //		waitTilHalted();
    StringBuilder sb = new StringBuilder();
    sb.append("Num Type           Disp Enb Address    What" + m_newline);
    // our list of breakpoints
    int count = breakpointCount();
    for (int i = 0; i < count; i++) {
        BreakAction b = breakpointAt(i);
        int status = b.getStatus();
        boolean isResolved = (status == BreakAction.RESOLVED);
        Location l = b.getLocation();
        SourceFile file = (l != null) ? l.getFile() : null;
        String funcName = (file == null) ? null : file.getFunctionNameForLine(m_session, l.getLine());
        boolean singleSwf = b.isSingleSwf();
        int cmdCount = b.getCommandCount();
        int hits = b.getHits();
        String cond = b.getConditionString();
        boolean silent = b.isSilent();
        int offset = adjustOffsetForUnitTests((file == null) ? 0 : file.getOffsetForLine(l.getLine()));
        int num = b.getId();
        FieldFormat.formatLong(sb, num, 3);
        sb.append(" breakpoint     ");
        if (b.isAutoDisable())
            sb.append("dis  ");
        else if (b.isAutoDelete())
            sb.append("del  ");
        else
            sb.append("keep ");
        if (b.isEnabled())
            sb.append("y   ");
        else
            sb.append("n   ");
        //$NON-NLS-1$
        sb.append("0x");
        FieldFormat.formatLongToHex(sb, offset, 8);
        sb.append(' ');
        if (funcName != null) {
            Map<String, Object> args = new HashMap<String, Object>();
            //$NON-NLS-1$
            args.put("functionName", funcName);
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("inFunctionAt", args));
        }
        if (file != null) {
            sb.append(file.getName());
            if (isResolved && singleSwf) {
                //$NON-NLS-1$
                sb.append("#");
                sb.append(file.getId());
            }
            sb.append(':');
            sb.append(l.getLine());
        } else {
            String expr = b.getBreakpointExpression();
            if (expr != null)
                sb.append(expr);
        }
        switch(status) {
            case BreakAction.UNRESOLVED:
                //$NON-NLS-1$
                sb.append(getLocalizationManager().getLocalizedTextString("breakpointNotYetResolved"));
                break;
            case BreakAction.AMBIGUOUS:
                //$NON-NLS-1$
                sb.append(getLocalizationManager().getLocalizedTextString("breakpointAmbiguous"));
                break;
            case BreakAction.NOCODE:
                //$NON-NLS-1$
                sb.append(getLocalizationManager().getLocalizedTextString("breakpointNoCode"));
                break;
        }
        // if a single swf break action then append more info
        if (singleSwf && isResolved) {
            try {
                SwfInfo info = m_fileInfo.swfForFile(file);
                Map<String, Object> swfArgs = new HashMap<String, Object>();
                //$NON-NLS-1$
                swfArgs.put("swf", FileInfoCache.nameOfSwf(info));
                //$NON-NLS-1$
                sb.append(getLocalizationManager().getLocalizedTextString("inSwf", swfArgs));
            } catch (NullPointerException npe) {
                // can't find the swf
                //$NON-NLS-1$
                sb.append(getLocalizationManager().getLocalizedTextString("nonRestorable"));
            }
        }
        sb.append(m_newline);
        //$NON-NLS-1$
        final String INDENT = "        ";
        // state our condition if we have one
        if (cond != null && cond.length() > 0) {
            sb.append(INDENT);
            Map<String, Object> args = new HashMap<String, Object>();
            //$NON-NLS-1$
            args.put("breakpointCondition", cond);
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString(getLocalizationManager().getLocalizedTextString("stopOnlyIfConditionMet", args)));
            sb.append(m_newline);
        }
        // now if its been hit, lets state the fact
        if (hits > 0) {
            sb.append(INDENT);
            Map<String, Object> args = new HashMap<String, Object>();
            //$NON-NLS-1$
            args.put("count", Integer.toString(hits));
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("breakpointAlreadyHit", args));
            sb.append(m_newline);
        }
        // silent?
        if (silent) {
            sb.append(INDENT);
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("silentBreakpoint") + m_newline);
        }
        // now if any commands are trailing then we pump them out
        for (int j = 0; j < cmdCount; j++) {
            sb.append(INDENT);
            sb.append(b.commandAt(j));
            sb.append(m_newline);
        }
    }
    int wcount = watchpointCount();
    for (int k = 0; k < wcount; k++) {
        WatchAction b = watchpointAt(k);
        int id = b.getId();
        FieldFormat.formatLong(sb, id, 4);
        int flags = b.getKind();
        switch(flags) {
            case WatchKind.READ:
                sb.append("rd watchpoint  ");
                break;
            case WatchKind.WRITE:
                sb.append("wr watchpoint  ");
                break;
            case WatchKind.READWRITE:
            default:
                sb.append("watchpoint     ");
                break;
        }
        sb.append("keep ");
        sb.append("y   ");
        //$NON-NLS-1$
        sb.append("           ");
        sb.append(b.getExpr());
        sb.append(m_newline);
    }
    int ccount = catchpointCount();
    for (int k = 0; k < ccount; k++) {
        CatchAction c = catchpointAt(k);
        int id = c.getId();
        FieldFormat.formatLong(sb, id, 4);
        String typeToCatch = c.getTypeToCatch();
        if (typeToCatch == null)
            //$NON-NLS-1$
            typeToCatch = "*";
        sb.append("catch          ");
        sb.append("keep ");
        sb.append("y   ");
        //$NON-NLS-1$
        sb.append("           ");
        sb.append(typeToCatch);
        sb.append(m_newline);
    }
    out(sb.toString());
}
Also used : HashMap(java.util.HashMap) SwfInfo(flash.tools.debugger.SwfInfo) DSwfInfo(flash.tools.debugger.concrete.DSwfInfo) SourceFile(flash.tools.debugger.SourceFile) Location(flash.tools.debugger.Location)

Aggregations

SourceFile (flash.tools.debugger.SourceFile)30 Location (flash.tools.debugger.Location)15 HashMap (java.util.HashMap)13 InProgressException (flash.tools.debugger.InProgressException)9 Map (java.util.Map)9 ParseException (java.text.ParseException)7 NotConnectedException (flash.tools.debugger.NotConnectedException)6 SwfInfo (flash.tools.debugger.SwfInfo)5 PlayerDebugException (flash.tools.debugger.PlayerDebugException)4 DSwfInfo (flash.tools.debugger.concrete.DSwfInfo)4 NoResponseException (flash.tools.debugger.NoResponseException)3 ArrayList (java.util.ArrayList)3 SourceBreakpoint (com.nextgenactionscript.vscode.debug.requests.SourceBreakpoint)2 Breakpoint (com.nextgenactionscript.vscode.debug.responses.Breakpoint)2 Frame (flash.tools.debugger.Frame)2 NotSupportedException (flash.tools.debugger.NotSupportedException)2 NotSuspendedException (flash.tools.debugger.NotSuspendedException)2 SuspendedException (flash.tools.debugger.SuspendedException)2 Variable (flash.tools.debugger.Variable)2 VersionException (flash.tools.debugger.VersionException)2