Fix bugs in debugger

This commit is contained in:
Alexey Andreev 2019-02-22 17:19:19 +03:00
parent 2095e52dc2
commit a8f1940df3
2 changed files with 24 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import com.carrotsearch.hppc.ObjectIntHashMap;
import com.carrotsearch.hppc.ObjectIntMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@ -59,7 +60,11 @@ public final class LocationGraphBuilder {
Visitor visitor = new Visitor();
node.acceptVisitor(visitor);
Graph graph = visitor.builder.build();
TextLocation[][] locations = propagate(visitor.locations.toArray(new TextLocation[0]), graph);
for (int terminal : visitor.nodes) {
visitor.terminalNodes.set(terminal);
}
TextLocation[][] locations = propagate(visitor.locations.toArray(new TextLocation[0]), graph,
visitor.terminalNodes);
Map<TextLocation, Set<TextLocation>> builder = new LinkedHashMap<>();
for (int i = 0; i < graph.size(); ++i) {
@ -70,6 +75,11 @@ public final class LocationGraphBuilder {
}
}
}
if (visitor.terminalNodes.get(i)) {
for (TextLocation loc : locations[i]) {
builder.computeIfAbsent(loc, k -> new LinkedHashSet<>()).add(null);
}
}
}
Map<TextLocation, TextLocation[]> result = new LinkedHashMap<>();
@ -79,7 +89,7 @@ public final class LocationGraphBuilder {
return result;
}
private static TextLocation[][] propagate(TextLocation[] locations, Graph graph) {
private static TextLocation[][] propagate(TextLocation[] locations, Graph graph, BitSet terminal) {
List<Set<TextLocation>> result = new ArrayList<>();
boolean[] stop = new boolean[graph.size()];
IntDeque queue = new IntArrayDeque();
@ -117,6 +127,7 @@ public final class LocationGraphBuilder {
IdentifiedStatement defaultContinueTarget;
GraphBuilder builder = new GraphBuilder();
List<TextLocation> locations = new ArrayList<>();
BitSet terminalNodes = new BitSet();
@Override
protected void afterVisit(Expr expr) {
@ -265,6 +276,9 @@ public final class LocationGraphBuilder {
public void visit(ReturnStatement statement) {
super.visit(statement);
setLocation(statement.getLocation());
for (int node : nodes) {
terminalNodes.set(node);
}
nodes = EMPTY;
}

View File

@ -108,6 +108,7 @@ public class Debugger {
return jsStep(enterMethod);
}
Set<JavaScriptLocation> successors = new HashSet<>();
boolean first = true;
for (CallFrame frame : callStack) {
boolean exits;
String script = frame.getOriginalLocation().getScript();
@ -129,7 +130,13 @@ public class Debugger {
if (!exits) {
break;
}
enterMethod = true;
enterMethod = false;
if (!first && frame.getLocation() != null) {
for (GeneratedLocation location : debugInfo.getGeneratedLocations(frame.getLocation())) {
successors.add(new JavaScriptLocation(script, location.getLine(), location.getColumn()));
}
}
first = false;
}
List<Promise<Void>> jsBreakpointPromises = new ArrayList<>();