Search in sources :

Example 16 with SourceFile

use of flash.tools.debugger.SourceFile in project vscode-nextgenas by BowlerHatLLC.

the class SWFDebugSession method setBreakpoints.

public void setBreakpoints(Response response, SetBreakpointsRequest.SetBreakpointsArguments arguments) {
    String path = arguments.source.path;
    Path pathAsPath = Paths.get(path);
    List<Breakpoint> breakpoints = new ArrayList<>();
    for (int i = 0, count = arguments.breakpoints.length; i < count; i++) {
        SourceBreakpoint sourceBreakpoint = arguments.breakpoints[i];
        int sourceLine = sourceBreakpoint.line;
        Breakpoint responseBreakpoint = new Breakpoint();
        responseBreakpoint.line = sourceLine;
        int fileId = -1;
        try {
            SwfInfo[] swfs = swfSession.getSwfs();
            for (SwfInfo swf : swfs) {
                SourceFile[] sourceFiles = swf.getSourceList(swfSession);
                for (SourceFile sourceFile : sourceFiles) {
                    //file system case sensitivity.
                    if (pathAsPath.equals(Paths.get(sourceFile.getFullPath())) && (path.endsWith(FILE_EXTENSION_AS) || path.endsWith(FILE_EXTENSION_MXML))) {
                        fileId = sourceFile.getId();
                        break;
                    }
                }
                if (fileId != -1) {
                    break;
                }
            }
            if (fileId == -1) {
                //either the file was not found, or it has an unsupported
                //extension
                responseBreakpoint.verified = false;
            } else {
                Location breakpointLocation = swfSession.setBreakpoint(fileId, sourceLine);
                if (breakpointLocation != null) {
                    //I don't know if the line could change, but might as well
                    //use the one returned by the location
                    responseBreakpoint.line = breakpointLocation.getLine();
                    responseBreakpoint.verified = true;
                } else {
                    //setBreakpoint() may return null if the breakpoint could
                    //not be set. that's fine. the user will see that the
                    //breakpoint is not verified, so it's fine.
                    responseBreakpoint.verified = false;
                }
            }
        } catch (InProgressException e) {
            e.printStackTrace(System.err);
            responseBreakpoint.verified = false;
        } catch (NoResponseException e) {
            e.printStackTrace(System.err);
            responseBreakpoint.verified = false;
        } catch (NotConnectedException e) {
            e.printStackTrace(System.err);
            responseBreakpoint.verified = false;
        }
        breakpoints.add(responseBreakpoint);
    }
    sendResponse(response, new SetBreakpointsResponseBody(breakpoints));
}
Also used : Path(java.nio.file.Path) SourceBreakpoint(com.nextgenactionscript.vscode.debug.requests.SourceBreakpoint) Breakpoint(com.nextgenactionscript.vscode.debug.responses.Breakpoint) InProgressException(flash.tools.debugger.InProgressException) NotConnectedException(flash.tools.debugger.NotConnectedException) SwfInfo(flash.tools.debugger.SwfInfo) ArrayList(java.util.ArrayList) SetBreakpointsResponseBody(com.nextgenactionscript.vscode.debug.responses.SetBreakpointsResponseBody) SourceBreakpoint(com.nextgenactionscript.vscode.debug.requests.SourceBreakpoint) Breakpoint(com.nextgenactionscript.vscode.debug.responses.Breakpoint) SourceBreakpoint(com.nextgenactionscript.vscode.debug.requests.SourceBreakpoint) SourceFile(flash.tools.debugger.SourceFile) NoResponseException(flash.tools.debugger.NoResponseException) Location(flash.tools.debugger.Location)

Example 17 with SourceFile

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

the class DebugCLI method tryResolveBreakpoint.

/**
	 * Try to resolve one breakpoint.  We do this every time a new ABC or
	 * SWF is loaded.
	 * @param b the breakpoint to resolve (it's okay if it's already resolved)
	 * @param sb a StringBuffer to which any messages for are appended;
	 * 			to the user.
	 * @return true if the breakpoint is resolved
	 * @throws AmbiguousException
	 * @throws NullPointerException 
	 */
private boolean tryResolveBreakpoint(BreakAction b, StringBuffer sb) throws AmbiguousException {
    int status = b.getStatus();
    boolean resolved = (status == BreakAction.RESOLVED);
    if (// we don't do anything for RESOLVED or AMBIGUOUS
    status == BreakAction.UNRESOLVED) {
        /* wait a bit if we are not halted */
        try {
            waitTilHalted();
            // a filename and line number.
            if (enableBreakpoint(b, b.isAutoDisable(), b.isAutoDelete())) {
                resolved = true;
            } else {
                int module = propertyGet(LIST_MODULE);
                int line = propertyGet(LIST_LINE);
                String arg = b.getBreakpointExpression();
                if (arg != null) {
                    int[] result = parseLocationArg(module, line, arg);
                    // whoo-hoo, it resolved!
                    module = result[0];
                    line = result[1];
                    // use module SourceFile to denote the name of file in which we wish to set a breakpoint
                    SourceFile f = m_fileInfo.getFile(module);
                    LocationCollection col = enableBreak(f, line);
                    if (col.isEmpty())
                        //$NON-NLS-1$
                        throw new NullPointerException(getLocalizationManager().getLocalizedTextString("noExecutableCode"));
                    b.setLocations(col);
                    Location l = col.first();
                    SourceFile file = (l != null) ? l.getFile() : null;
                    String funcName = (file == null) ? null : file.getFunctionNameForLine(m_session, l.getLine());
                    Map args = new HashMap();
                    String formatString;
                    //$NON-NLS-1$
                    args.put("breakpointNumber", Integer.toString(b.getId()));
                    String filename = file.getName();
                    if (b.isSingleSwf() && file != null) {
                        //$NON-NLS-1$
                        filename = filename + "#" + file.getId();
                    }
                    //$NON-NLS-1$
                    args.put("file", filename);
                    //$NON-NLS-1$
                    args.put("line", new Integer(l.getLine()));
                    if (funcName != null) {
                        //$NON-NLS-1$
                        args.put("functionName", funcName);
                        //$NON-NLS-1$
                        formatString = "resolvedBreakpointToFunction";
                    } else {
                        //$NON-NLS-1$
                        formatString = "resolvedBreakpointToFile";
                    }
                    sb.append(getLocalizationManager().getLocalizedTextString(formatString, args));
                    sb.append(m_newline);
                    sb.append(m_newline);
                    resolved = true;
                }
            }
        } catch (NotConnectedException e) {
        // Ignore
        } catch (NoMatchException e) {
        // Okay, it's still not resolved; do nothing
        } catch (ParseException e) {
            // this shouldn't happen
            if (Trace.error)
                Trace.trace(e.toString());
        } catch (AmbiguousException e) {
            b.setStatus(BreakAction.AMBIGUOUS);
            // rethrow
            throw e;
        } catch (NullPointerException e) {
            b.setStatus(BreakAction.NOCODE);
            // rethrow
            throw e;
        }
    }
    return resolved;
}
Also used : NotConnectedException(flash.tools.debugger.NotConnectedException) HashMap(java.util.HashMap) SourceFile(flash.tools.debugger.SourceFile) ParseException(java.text.ParseException) Map(java.util.Map) HashMap(java.util.HashMap) Location(flash.tools.debugger.Location)

Example 18 with SourceFile

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

the class DebugCLI method doBreak.

/**
	 * Set a breakpoint
	 */
void doBreak() throws NotConnectedException {
    /* wait a bit if we are not halted */
    waitTilHalted();
    int module = propertyGet(LIST_MODULE);
    int line = propertyGet(LIST_LINE);
    String arg = null;
    /* currentXXX may NOT be invalid! */
    try {
        if (hasMoreTokens()) {
            arg = nextToken();
            int[] result = parseLocationArg(module, line, arg);
            module = result[0];
            line = result[1];
        } else {
            // no parameter mean use current location;  null pointer if nothing works
            Location l = getCurrentLocation();
            SourceFile file = l.getFile();
            module = file.getId();
            line = l.getLine();
        }
        //			// check to see if there are any existing breakpoints at this file/line
        //			LinkedList existingBreakpoints = new LinkedList();
        //			int start = 0;
        //			for (;;)
        //			{
        //				int bp = breakpointIndexOf(module, line, start, true);
        //				if (bp == -1)
        //					break; // no more matches
        //				boolean isEnabled = breakpointAt(bp).isEnabled();
        //				existingBreakpoints.add("" + bp + (isEnabled ? "" : " (disabled)"));
        //			}
        //			if (existingBreakpoints.size() > 0)
        //			{
        //				String
        //			}
        // go off; create it and set it
        // throws npe if not able to set
        BreakAction b = addBreakpoint(module, line);
        Location l = b.getLocation();
        int which = b.getId();
        String name = l.getFile().getName();
        int offset = adjustOffsetForUnitTests(l.getFile().getOffsetForLine(line));
        Map<String, Object> args = new HashMap<String, Object>();
        //$NON-NLS-1$
        args.put("breakpointNumber", Integer.toString(which));
        //$NON-NLS-1$
        args.put("file", name);
        //$NON-NLS-1$
        args.put("line", Integer.toString(line));
        String formatString;
        if (offset != 0) {
            //$NON-NLS-1$ //$NON-NLS-2$
            args.put("offset", "0x" + Integer.toHexString(offset));
            //$NON-NLS-1$
            formatString = "createdBreakpointWithOffset";
        } else {
            //$NON-NLS-1$
            formatString = "createdBreakpoint";
        }
        out(getLocalizationManager().getLocalizedTextString(formatString, args));
        // worked so add it to our tracking state
        propertyPut(BPNUM, which);
    } catch (ParseException pe) {
        err(pe.getMessage());
    } catch (AmbiguousException ae) {
        err(ae.getMessage());
    } catch (NoMatchException nme) {
        // We couldn't find a function name or filename which matched what
        // the user entered.  Do *not* fail; instead, just save this breakpoint
        // away, and later, as more ABCs get loaded from the SWF, we may be
        // able to resolve this breakpoint.
        BreakAction b = addUnresolvedBreakpoint(arg);
        Map<String, Object> args = new HashMap<String, Object>();
        //$NON-NLS-1$
        args.put("breakpointNumber", Integer.toString(b.getId()));
        //$NON-NLS-1$
        out(getLocalizationManager().getLocalizedTextString("breakpointCreatedButNotYetResolved", args));
        // add it to our tracking state
        propertyPut(BPNUM, b.getId());
    } catch (NullPointerException npe) {
        String filename;
        try {
            //$NON-NLS-1$
            filename = m_fileInfo.getFile(module).getName() + "#" + module;
        } catch (Exception e) {
            Map<String, Object> args = new HashMap<String, Object>();
            //$NON-NLS-1$
            args.put("fileNumber", Integer.toString(module));
            //$NON-NLS-1$
            filename = getLocalizationManager().getLocalizedTextString("fileNumber", args);
        }
        Map<String, Object> args = new HashMap<String, Object>();
        //$NON-NLS-1$
        args.put("filename", filename);
        //$NON-NLS-1$
        args.put("line", Integer.toString(line));
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("breakpointNotSetNoCode", args));
    }
}
Also used : HashMap(java.util.HashMap) VersionException(flash.tools.debugger.VersionException) PlayerFaultException(flash.tools.debugger.expression.PlayerFaultException) ParseException(java.text.ParseException) NotSupportedException(flash.tools.debugger.NotSupportedException) PlayerDebugException(flash.tools.debugger.PlayerDebugException) NotSuspendedException(flash.tools.debugger.NotSuspendedException) EOFException(java.io.EOFException) SuspendedException(flash.tools.debugger.SuspendedException) FileNotFoundException(java.io.FileNotFoundException) InProgressException(flash.tools.debugger.InProgressException) NoResponseException(flash.tools.debugger.NoResponseException) SocketException(java.net.SocketException) NoSuchVariableException(flash.tools.debugger.expression.NoSuchVariableException) SocketTimeoutException(java.net.SocketTimeoutException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) NotConnectedException(flash.tools.debugger.NotConnectedException) SourceFile(flash.tools.debugger.SourceFile) ParseException(java.text.ParseException) Map(java.util.Map) HashMap(java.util.HashMap) Location(flash.tools.debugger.Location)

Example 19 with SourceFile

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

the class DebugCLI method doList.

/*
     * We accept zero, one or two args for this command. Zero args
     * means list the next 10 line around the previous listing.  One argument
     * specifies a line and 10 lines are listed around that line.  Two arguments
     * with a command between specifies starting and ending lines.
     */
void doList() {
    /* currentXXX may NOT be invalid! */
    int currentModule = propertyGet(LIST_MODULE);
    int currentLine = propertyGet(LIST_LINE);
    int listsize = propertyGet(LIST_SIZE);
    String arg1 = null;
    int module1 = currentModule;
    int line1 = currentLine;
    String arg2 = null;
    int line2 = currentLine;
    int numLines = 0;
    try {
        if (hasMoreTokens()) {
            arg1 = nextToken();
            if (//$NON-NLS-1$
            arg1.equals("-")) {
                // move back two times the listing size and if listsize is odd then move forward one
                line1 = line2 = line1 - (2 * listsize);
            } else {
                int[] result = parseLocationArg(currentModule, currentLine, arg1);
                module1 = result[0];
                line2 = line1 = result[1];
                if (hasMoreTokens()) {
                    arg2 = nextToken();
                    line2 = parseLineArg(module1, arg2);
                }
            }
        }
        /**
			 * Check for a few error conditions, otherwise we'll write a listing!
			 */
        if (hasMoreTokens()) {
            //$NON-NLS-1$
            err(getLocalizationManager().getLocalizedTextString("lineJunk"));
        } else {
            int half = listsize / 2;
            SourceFile file = m_fileInfo.getFile(module1);
            numLines = file.getLineCount();
            int newLine;
            if (//$NON-NLS-1$
            numLines == 1 && file.getLine(1).equals("")) {
                // there's no source in the file at all!
                // this presumably means that the source file isn't in the current directory
                //$NON-NLS-1$
                err(getLocalizationManager().getLocalizedTextString("sourceFileNotFound"));
                newLine = currentLine;
            } else {
                // pressing return is ok, otherwise throw the exception
                if (line1 > numLines && arg1 != null)
                    throw new IndexOutOfBoundsException();
                /* if no arg2 then user requested the next N lines around something */
                if (arg2 == null) {
                    line2 = line1 + (half) - 1;
                    line1 = line1 - (listsize - half);
                }
                /* adjust our range of lines to ensure we conform */
                if (line1 < 1) {
                    /* shrink line 1, grow line2 */
                    line2 += -(line1 - 1);
                    line1 = 1;
                }
                if (line2 > numLines)
                    line2 = numLines;
                /* nothing to display */
                if (line1 > line2)
                    throw new IndexOutOfBoundsException();
                /* now do it! */
                SourceFile source = m_fileInfo.getFile(module1);
                for (int i = line1; i <= line2; i++) outputSource(module1, i, source.getLine(i));
                // add one if even, 2 for odd;
                newLine = line2 + half + (((listsize % 2) == 0) ? 1 : 2);
            }
            /* save away valid context */
            propertyPut(LIST_MODULE, module1);
            propertyPut(LIST_LINE, newLine);
            //$NON-NLS-1$
            m_repeatLine = "list";
        /* allow repeated listing by typing CR */
        }
    } catch (IndexOutOfBoundsException iob) {
        //$NON-NLS-1$
        String name = "#" + module1;
        Map<String, Object> args = new HashMap<String, Object>();
        //$NON-NLS-1$
        args.put("line", Integer.toString(line1));
        //$NON-NLS-1$
        args.put("filename", name);
        //$NON-NLS-1$
        args.put("total", Integer.toString(numLines));
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("lineNumberOutOfRange", args));
    } catch (AmbiguousException ae) {
        err(ae.getMessage());
    } catch (NoMatchException nme) {
        // TODO [mmorearty]: try to find a matching source file
        err(nme.getMessage());
    } catch (NullPointerException npe) {
        //$NON-NLS-1$
        err(getLocalizationManager().getLocalizedTextString("noFilesFound"));
    } catch (ParseException pe) {
        err(pe.getMessage());
    }
}
Also used : SourceFile(flash.tools.debugger.SourceFile) ParseException(java.text.ParseException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with SourceFile

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

the class DebugCLI method appendFrameInfo.

/**
	 * Spit out frame information for a given frame number 
	 */
boolean appendFrameInfo(StringBuilder sb, Frame ctx, int frameNumber, boolean showThis, boolean showFileId) throws PlayerDebugException {
    boolean validFrame = true;
    // some formatting properties
    int i = frameNumber;
    Location loc = ctx.getLocation();
    SourceFile file = loc.getFile();
    int line = loc.getLine();
    //$NON-NLS-1$
    String name = (file == null) ? "<null>" : file.getName();
    String sig = ctx.getCallSignature();
    String func = extractFunctionName(sig);
    // file == null or line < 0 appears to be a terminator for stack info
    if (file == null && line < 0) {
        validFrame = false;
    } else {
        Variable[] var = ctx.getArguments(m_session);
        Variable dis = ctx.getThis(m_session);
        boolean displayArgs = (func != null) || (var != null);
        sb.append('#');
        FieldFormat.formatLong(sb, i, 3);
        sb.append(' ');
        if (showThis && dis != null) {
            ExpressionCache.appendVariable(sb, dis);
            //$NON-NLS-1$
            sb.append(".");
        }
        if (func != null)
            sb.append(func);
        if (displayArgs) {
            sb.append('(');
            for (int j = 0; j < var.length; j++) {
                Variable v = var[j];
                sb.append(v.getName());
                sb.append('=');
                ExpressionCache.appendVariableValue(sb, v.getValue());
                if ((j + 1) < var.length)
                    //$NON-NLS-1$
                    sb.append(", ");
            }
            //$NON-NLS-1$
            sb.append(")");
            //$NON-NLS-1$
            sb.append(getLocalizationManager().getLocalizedTextString("atFilename"));
        }
        sb.append(name);
        // if this file is currently being filtered put the source file id after it
        if (file != null && (showFileId || !m_fileInfo.inFileList(file))) {
            sb.append('#');
            sb.append(file.getId());
        }
        sb.append(':');
        sb.append(line);
    }
    return validFrame;
}
Also used : Variable(flash.tools.debugger.Variable) 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