use of flash.tools.debugger.Location 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));
}
use of flash.tools.debugger.Location 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;
}
use of flash.tools.debugger.Location 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));
}
}
use of flash.tools.debugger.Location 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;
}
use of flash.tools.debugger.Location in project intellij-plugins by JetBrains.
the class DebugCLI method processBreak.
/**
* Our logic for handling a break condition.
*
* @return some hit breakpoint requested silence, shhhh!
*/
boolean processBreak(boolean postStep, StringBuilder sb) throws NotConnectedException {
Location l = getCurrentLocation();
if (l == null || l.getFile() == null)
return false;
int fileId = l.getFile().getId();
int line = l.getLine();
boolean isSilent = false;
boolean bpHit = false;
boolean stoppedDueToBp = false;
int count = breakpointCount();
boolean[] markedForRemoval = new boolean[count];
boolean previousResume = m_requestResume;
for (int i = 0; i < count; i++) {
BreakAction a = breakpointAt(i);
if (a.locationMatches(fileId, line)) {
/**
* Note that it appears that we stopped due to hitting a hard breakpoint
* Now if the breakpoint is conditional it may eval to false, meaning we
* won't stop here, otherwise we will process the breakpoint.
*/
stoppedDueToBp = (m_session.suspendReason() == SuspendReason.Breakpoint);
if (shouldBreak(a, fileId, line)) {
// its a hit
bpHit = true;
a.hit();
isSilent = (isSilent) ? true : a.isSilent();
// autodelete, autodisable
if (a.isAutoDisable())
disableBreakpointAt(i);
if (a.isAutoDelete())
markedForRemoval[i] = true;
// now issue any commands that are attached to the breakpoint
int n = a.getCommandCount();
for (int j = 0; j < n; j++) issueCommand(a.commandAt(j), sb);
}
}
}
// kill them backwards so our i is acurate
for (int i = markedForRemoval.length - 1; i > -1; i--) if (markedForRemoval[i])
removeBreakpointAt(i);
/**
* Now we should request to resume only if it was due to
* breakpoints that were hit.
*
* For the first case, we hit a conditional breakpoint that
* eval'd to false, resulting in bpHit == false. Thus we
* want to resume and additionally if we were stepping, we'd
* like to do so 'softly' that is without loosing the stepping
* information on the Player.
*
* For the 2nd case, we hit a breakpoint and we executed
* commands that resulted in a m_requestResume.
*/
if (stoppedDueToBp && !bpHit) {
m_requestResume = true;
// resume without losing our stepping
m_stepResume = postStep;
// do so quietly
isSilent = true;
} else if (stoppedDueToBp && bpHit && m_requestResume && !previousResume) {
m_requestResume = true;
// resume as we would
m_stepResume = postStep;
processDisplay(sb);
}
// If we aren't continuing, then show display variables
if (!m_requestResume)
processDisplay(sb);
return isSilent;
}
Aggregations