fix: debugger concurrency issues

This commit is contained in:
TopchetoEU 2024-12-28 13:19:53 +02:00
parent 4c53689d9c
commit 9ce0504948
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
2 changed files with 58 additions and 45 deletions

View File

@ -159,8 +159,10 @@ public class DebugServer {
} }
public void awaitConnection() throws InterruptedException { public void awaitConnection() throws InterruptedException {
synchronized (connNotifier) {
connNotifier.wait(); connNotifier.wait();
} }
}
public void run(InetSocketAddress address) { public void run(InetSocketAddress address) {
try { try {

View File

@ -1032,15 +1032,20 @@ public class SimpleDebugger implements Debugger {
} }
mappings.put(body, map); mappings.put(body, map);
} }
private boolean instructionLock;
@Override public boolean onInstruction(Environment env, Frame cf, Instruction instruction, Value returnVal, EngineException error, boolean caught) { @Override public boolean onInstruction(Environment env, Frame cf, Instruction instruction, Value returnVal, EngineException error, boolean caught) {
if (!enabled) return false; if (!enabled) return false;
if (instructionLock) return false;
instructionLock = true;
try {
boolean isBreakpointable; boolean isBreakpointable;
Location loc; Location loc;
DebugFrame frame; DebugFrame frame;
BreakpointType bptType; BreakpointType bptType;
synchronized (this) {
frame = getFrame(cf); frame = getFrame(cf);
var map = DebugContext.get(env).getMap(frame.frame.function); var map = DebugContext.get(env).getMap(frame.frame.function);
@ -1077,6 +1082,8 @@ public class SimpleDebugger implements Debugger {
instruction.params.length == 1 && instruction.params.length == 1 &&
instruction.get(0).equals("debug") instruction.get(0).equals("debug")
) pauseDebug(env, null); ) pauseDebug(env, null);
synchronized (this) {
} }
while (enabled) { while (enabled) {
@ -1121,6 +1128,10 @@ public class SimpleDebugger implements Debugger {
return false; return false;
} }
finally {
instructionLock = false;
}
}
@Override public synchronized void onFramePush(Environment env, Frame frame) { @Override public synchronized void onFramePush(Environment env, Frame frame) {
var prevFrame = currFrame; var prevFrame = currFrame;
updateFrames(env, 0); updateFrames(env, 0);