fix: debugger hanging sometimes
This commit is contained in:
parent
c6e6425c7e
commit
e4c9a8756e
@ -96,7 +96,6 @@ public class Context implements Extensions {
|
|||||||
|
|
||||||
public Context pushFrame(CodeFrame frame) {
|
public Context pushFrame(CodeFrame frame) {
|
||||||
var res = new Context(this, frame.function.environment, frame, engine, stackSize + 1);
|
var res = new Context(this, frame.function.environment, frame, engine, stackSize + 1);
|
||||||
DebugContext.get(res).onFramePush(res, frame);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,34 +109,48 @@ public class SimpleDebugger implements Debugger {
|
|||||||
public ObjectValue local, capture, global, valstack;
|
public ObjectValue local, capture, global, valstack;
|
||||||
public JSONMap serialized;
|
public JSONMap serialized;
|
||||||
public Location location;
|
public Location location;
|
||||||
public boolean debugData = false;
|
|
||||||
|
|
||||||
public void updateLoc(Location loc) {
|
public void updateLoc(Location loc) {
|
||||||
if (loc == null) return;
|
if (loc == null) return;
|
||||||
this.location = loc;
|
this.location = loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Frame(Context ctx, CodeFrame frame, int id) {
|
public Frame(CodeFrame frame, int id) {
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.func = frame.function;
|
this.func = frame.function;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
this.global = frame.function.environment.global.obj;
|
this.global = frame.function.environment.global.obj;
|
||||||
this.local = frame.getLocalScope(ctx, true);
|
this.local = frame.getLocalScope(true);
|
||||||
this.capture = frame.getCaptureScope(ctx, true);
|
this.capture = frame.getCaptureScope(true);
|
||||||
this.local.setPrototype(ctx, capture);
|
this.local.setPrototype(frame.ctx, capture);
|
||||||
this.capture.setPrototype(ctx, global);
|
this.capture.setPrototype(frame.ctx, global);
|
||||||
this.valstack = frame.getValStackScope(ctx);
|
this.valstack = frame.getValStackScope();
|
||||||
debugData = true;
|
|
||||||
|
|
||||||
this.serialized = new JSONMap()
|
this.serialized = new JSONMap()
|
||||||
.set("callFrameId", id + "")
|
.set("callFrameId", id + "")
|
||||||
.set("functionName", func.name)
|
.set("functionName", func.name)
|
||||||
.set("scopeChain", new JSONList()
|
.set("scopeChain", new JSONList()
|
||||||
.add(new JSONMap().set("type", "local").set("name", "Local Scope").set("object", serializeObj(ctx, local)))
|
.add(new JSONMap()
|
||||||
.add(new JSONMap().set("type", "closure").set("name", "Closure").set("object", serializeObj(ctx, capture)))
|
.set("type", "local")
|
||||||
.add(new JSONMap().set("type", "global").set("name", "Global Scope").set("object", serializeObj(ctx, global)))
|
.set("name", "Local Scope")
|
||||||
.add(new JSONMap().set("type", "other").set("name", "Value Stack").set("object", serializeObj(ctx, valstack)))
|
.set("object", serializeObj(frame.ctx, local))
|
||||||
|
)
|
||||||
|
.add(new JSONMap()
|
||||||
|
.set("type", "closure")
|
||||||
|
.set("name", "Closure")
|
||||||
|
.set("object", serializeObj(frame.ctx, capture))
|
||||||
|
)
|
||||||
|
.add(new JSONMap()
|
||||||
|
.set("type", "global")
|
||||||
|
.set("name", "Global Scope")
|
||||||
|
.set("object", serializeObj(frame.ctx, global))
|
||||||
|
)
|
||||||
|
.add(new JSONMap()
|
||||||
|
.set("type", "other")
|
||||||
|
.set("name", "Value Stack")
|
||||||
|
.set("object", serializeObj(frame.ctx, valstack))
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,25 +245,29 @@ public class SimpleDebugger implements Debugger {
|
|||||||
return nextId++;
|
return nextId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized Frame getFrame(CodeFrame frame) {
|
||||||
|
if (!codeFrameToFrame.containsKey(frame)) {
|
||||||
|
var id = nextId();
|
||||||
|
var fr = new Frame(frame, id);
|
||||||
|
|
||||||
|
idToFrame.put(id, fr);
|
||||||
|
codeFrameToFrame.put(frame, fr);
|
||||||
|
|
||||||
|
return fr;
|
||||||
|
}
|
||||||
|
else return codeFrameToFrame.get(frame);
|
||||||
|
}
|
||||||
private synchronized void updateFrames(Context ctx) {
|
private synchronized void updateFrames(Context ctx) {
|
||||||
var frame = ctx.frame;
|
var frame = ctx.frame;
|
||||||
if (frame == null) return;
|
if (frame == null) return;
|
||||||
|
|
||||||
if (!codeFrameToFrame.containsKey(frame)) {
|
currFrame = getFrame(frame);
|
||||||
var id = nextId();
|
|
||||||
var fr = new Frame(ctx, frame, id);
|
|
||||||
|
|
||||||
idToFrame.put(id, fr);
|
|
||||||
codeFrameToFrame.put(frame, fr);
|
|
||||||
}
|
|
||||||
|
|
||||||
currFrame = codeFrameToFrame.get(frame);
|
|
||||||
}
|
}
|
||||||
private JSONList serializeFrames(Context ctx) {
|
private JSONList serializeFrames(Context ctx) {
|
||||||
var res = new JSONList();
|
var res = new JSONList();
|
||||||
|
|
||||||
for (var el : ctx.frames()) {
|
for (var el : ctx.frames()) {
|
||||||
var frame = codeFrameToFrame.get(el);
|
var frame = getFrame(el);
|
||||||
if (frame.location == null) continue;
|
if (frame.location == null) continue;
|
||||||
frame.serialized.set("location", serializeLocation(frame.location));
|
frame.serialized.set("location", serializeLocation(frame.location));
|
||||||
if (frame.location != null) res.add(frame.serialized);
|
if (frame.location != null) res.add(frame.serialized);
|
||||||
@ -894,9 +912,7 @@ public class SimpleDebugger implements Debugger {
|
|||||||
Frame frame;
|
Frame frame;
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
frame = codeFrameToFrame.get(cf);
|
frame = getFrame(cf);
|
||||||
|
|
||||||
if (!frame.debugData) return false;
|
|
||||||
|
|
||||||
if (instruction.location != null) frame.updateLoc(DebugContext.get(ctx).mapToCompiled(instruction.location));
|
if (instruction.location != null) frame.updateLoc(DebugContext.get(ctx).mapToCompiled(instruction.location));
|
||||||
loc = frame.location;
|
loc = frame.location;
|
||||||
|
Loading…
Reference in New Issue
Block a user