Skip to content

Commit

Permalink
swf-debug-adapter: Fix breakpoints inside <fx:Script> inside <fx:Comp…
Browse files Browse the repository at this point in the history
…onent> (closes #51)

It turns out that MXML results in multiple SourceFile objects with the same path, so we need to collect them all, and then try adding the breakpoint in each one.
  • Loading branch information
joshtynjala committed Oct 30, 2024
1 parent 3993c57 commit 7a68d97
Showing 1 changed file with 59 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,8 @@ public void setBreakpoints(Response response, SetBreakpointsRequest.SetBreakpoin
private List<Breakpoint> setBreakpoints(String path, SourceBreakpoint[] breakpoints) {
// start by trying to find the file ID for this path
Path pathAsPath = Paths.get(path);
SourceFile foundSourceFile = null;
// using MXML may create more than one source file with the same path
List<SourceFile> foundSourceFiles = new ArrayList<>();
boolean badExtension = false;
try {
SwfInfo[] swfs = swfSession.getSwfs();
Expand All @@ -1080,52 +1081,42 @@ private List<Breakpoint> setBreakpoints(String path, SourceBreakpoint[] breakpoi
if (pathAsPath.equals(sourceFilePath)) {
if (path.endsWith(FILE_EXTENSION_AS) || path.endsWith(FILE_EXTENSION_MXML)
|| path.endsWith(FILE_EXTENSION_HX)) {
foundSourceFile = sourceFile;
foundSourceFiles.add(sourceFile);
} else {
badExtension = true;
}
break;
}
}
if (foundSourceFile != null) {
}
for (IsolateWithState isolateWithState : isolates) {
if (foundSourceFiles.size() > 0) {
break;
}
}
if (foundSourceFile == null) {
for (IsolateWithState isolateWithState : isolates) {
Isolate isolate = isolateWithState.isolate;
IsolateSession isolateSession = swfSession.getWorkerSession(isolate.getId());
swfs = isolateSession.getSwfs();
for (SwfInfo swf : swfs) {
SourceFile[] sourceFiles = swf.getSourceList(swfSession);
for (SourceFile sourceFile : sourceFiles) {
Path sourceFilePath = null;
try {
String sourceFileFullPath = sourceFile.getFullPath();
sourceFilePath = Paths.get(sourceFileFullPath);
} catch (InvalidPathException e) {
Isolate isolate = isolateWithState.isolate;
IsolateSession isolateSession = swfSession.getWorkerSession(isolate.getId());
swfs = isolateSession.getSwfs();
for (SwfInfo swf : swfs) {
SourceFile[] sourceFiles = swf.getSourceList(swfSession);
for (SourceFile sourceFile : sourceFiles) {
Path sourceFilePath = null;
try {
String sourceFileFullPath = sourceFile.getFullPath();
sourceFilePath = Paths.get(sourceFileFullPath);
} catch (InvalidPathException e) {
badExtension = true;
continue;
}
// we can't check if the String paths are equal due to
// file system case sensitivity.
if (pathAsPath.equals(sourceFilePath)) {
if (path.endsWith(FILE_EXTENSION_AS) || path.endsWith(FILE_EXTENSION_MXML)
|| path.endsWith(FILE_EXTENSION_HX)) {
foundSourceFiles.add(sourceFile);
} else {
badExtension = true;
continue;
}
// we can't check if the String paths are equal due to
// file system case sensitivity.
if (pathAsPath.equals(sourceFilePath)) {
if (path.endsWith(FILE_EXTENSION_AS) || path.endsWith(FILE_EXTENSION_MXML)
|| path.endsWith(FILE_EXTENSION_HX)) {
foundSourceFile = sourceFile;
} else {
badExtension = true;
}
break;
}
}
if (foundSourceFile != null) {
break;
}
}
if (foundSourceFile != null) {
break;
}
}
}
} catch (InProgressException e) {
Expand All @@ -1137,13 +1128,13 @@ private List<Breakpoint> setBreakpoints(String path, SourceBreakpoint[] breakpoi
e.printStackTrace(new PrintWriter(writer));
sendErrorOutputEvent("Exception in debugger: " + writer.toString() + "\n");
}
if (foundSourceFile == null && !badExtension) {
if (foundSourceFiles.size() == 0 && !badExtension) {
// the file was not found, but it has a supported extension,
// so we'll try to add it again later.
// SWF is a streaming format, so not all bytecode is loaded
// immediately.
pendingBreakpoints.put(path, new PendingBreakpoints(breakpoints));
foundSourceFile = null;
foundSourceFiles.clear();
}
try {
// clear all old breakpoints for this file because our new list
Expand Down Expand Up @@ -1171,42 +1162,50 @@ private List<Breakpoint> setBreakpoints(String path, SourceBreakpoint[] breakpoi
responseBreakpoint.line = sourceLine;
responseBreakpoint.id = nextBreakpointID;
nextBreakpointID++;
if (foundSourceFile == null) {
if (foundSourceFiles.size() == 0) {
// we couldn't find the file, so we can't verify this breakpoint
responseBreakpoint.verified = false;
} else {
// we found the file, so let's try to add this breakpoint
// it may not work, but at least we tried!
responseBreakpoint.source = sourceFileToSource(foundSourceFile);
try {
Location breakpointLocation = swfSession.setBreakpoint(foundSourceFile.getId(), sourceLine);
if (breakpointLocation != null) {
verifyBreakpoint(path, breakpointLocation, sourceBreakpoint, responseBreakpoint);
}
if (!responseBreakpoint.verified) {
for (SourceFile foundSourceFile : foundSourceFiles) {
responseBreakpoint.source = sourceFileToSource(foundSourceFile);
try {
Location breakpointLocation = swfSession.setBreakpoint(foundSourceFile.getId(), sourceLine);
if (breakpointLocation != null) {
verifyBreakpoint(path, breakpointLocation, sourceBreakpoint, responseBreakpoint);
if (responseBreakpoint.verified) {
break;
}
}
for (IsolateWithState isolateWithState : isolates) {
Isolate isolate = isolateWithState.isolate;
IsolateSession isolateSession = swfSession.getWorkerSession(isolate.getId());
breakpointLocation = isolateSession.setBreakpoint(foundSourceFile.getId(), sourceLine);
if (breakpointLocation != null) {
verifyBreakpoint(path, breakpointLocation, sourceBreakpoint, responseBreakpoint);
break;
if (responseBreakpoint.verified) {
break;
}
}
}
if (responseBreakpoint.verified) {
break;
}
// setBreakpoint() may return null if the breakpoint
// could not be set. that's fine. the user will simply
// see that the breakpoint is not verified.
} catch (NoResponseException e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
sendErrorOutputEvent("Exception in debugger: " + writer.toString() + "\n");
responseBreakpoint.verified = false;
} catch (NotConnectedException e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
sendErrorOutputEvent("Exception in debugger: " + writer.toString() + "\n");
responseBreakpoint.verified = false;
}
// setBreakpoint() may return null if the breakpoint
// could not be set. that's fine. the user will simply
// see that the breakpoint is not verified.
} catch (NoResponseException e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
sendErrorOutputEvent("Exception in debugger: " + writer.toString() + "\n");
responseBreakpoint.verified = false;
} catch (NotConnectedException e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
sendErrorOutputEvent("Exception in debugger: " + writer.toString() + "\n");
responseBreakpoint.verified = false;
}
}
result.add(responseBreakpoint);
Expand Down

0 comments on commit 7a68d97

Please sign in to comment.