From 6c911927944f3fcfc4078368c52cdda2f05f9e6a Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 14 Dec 2022 16:50:18 +0100 Subject: [PATCH] Wasm: fix issues in debugger --- .../java/org/teavm/debugging/Debugger.java | 50 +++++++++++-------- .../teavm/chromerdp/ChromeRDPDebugger.java | 7 +-- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/teavm/debugging/Debugger.java b/core/src/main/java/org/teavm/debugging/Debugger.java index ac72912c7..793579d56 100644 --- a/core/src/main/java/org/teavm/debugging/Debugger.java +++ b/core/src/main/java/org/teavm/debugging/Debugger.java @@ -162,6 +162,17 @@ public class Debugger { return Promise.allVoid(jsBreakpointPromises); } + private Promise destroyTemporaryBreakpoints() { + var temporaryBreakpoints = new ArrayList<>(this.temporaryBreakpoints); + this.temporaryBreakpoints.clear(); + var promises = new ArrayList>(); + for (var jsBreakpoint : temporaryBreakpoints) { + promises.add(jsBreakpoint.destroy()); + } + callStack = null; + return Promise.allVoid(promises); + } + private boolean addJsBreakpoints(CallFrame frame, JavaScriptScript script, boolean enterMethod, Set successors) { var debugInfo = debugInformationMap.get(script); @@ -197,10 +208,10 @@ public class Debugger { var callAddresses = IntHashSet.from(wasmStepLocationsFinder.getCallAddresses()); var result = createTemporaryBreakpoints(locations, br -> { if (br != null && br.isValid() && callAddresses.contains(br.getLocation().getColumn())) { - javaScriptDebugger.stepInto(); - return false; + destroyTemporaryBreakpoints().thenVoid(x -> javaScriptDebugger.stepInto()); + return true; } - return true; + return false; }); return result.thenVoid(x -> javaScriptDebugger.stepOut()); } @@ -659,31 +670,26 @@ public class Debugger { } private void firePaused(JavaScriptBreakpoint breakpoint) { - var temporaryBreakpoints = new ArrayList<>(this.temporaryBreakpoints); var handler = temporaryBreakpointHandler; - this.temporaryBreakpoints.clear(); temporaryBreakpointHandler = null; - var promises = new ArrayList>(); - for (var jsBreakpoint : temporaryBreakpoints) { - promises.add(jsBreakpoint.destroy()); - } callStack = null; - Promise.allVoid(promises).thenVoid(v -> { - Breakpoint javaBreakpoint = null; - JavaScriptBreakpoint tmpBreakpoint = null; - if (breakpoint != null) { - if (temporaryBreakpoints.contains(breakpoint)) { - tmpBreakpoint = breakpoint; - } else { - javaBreakpoint = breakpointMap.get(breakpoint); - } + Breakpoint javaBreakpoint = null; + JavaScriptBreakpoint tmpBreakpoint = null; + if (breakpoint != null) { + if (temporaryBreakpoints.contains(breakpoint)) { + tmpBreakpoint = breakpoint; + } else { + javaBreakpoint = breakpointMap.get(breakpoint); } - if (handler == null || !handler.test(tmpBreakpoint)) { + } + if (handler == null || !handler.test(tmpBreakpoint)) { + var pausedAtBreakpoint = javaBreakpoint; + destroyTemporaryBreakpoints().thenVoid(v -> { for (var listener : getListeners()) { - listener.paused(javaBreakpoint); + listener.paused(pausedAtBreakpoint); } - } - }); + }); + } } private void fireAttached() { diff --git a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java index a1a915ec0..d0d6ea55a 100644 --- a/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java +++ b/tools/chrome-rdp/src/main/java/org/teavm/chromerdp/ChromeRDPDebugger.java @@ -484,9 +484,10 @@ public class ChromeRDPDebugger extends BaseChromeRDPDebugger implements JavaScri return new RDPValue(this, null, remoteValue.getType(), remoteValue.getObjectId(), true); } - default: - return new RDPValue(this, remoteValue.getValue().asText(), remoteValue.getType(), - remoteValue.getObjectId(), false); + default: { + var valueAsText = remoteValue.getValue() != null ? remoteValue.getValue().asText() : "null"; + return new RDPValue(this, valueAsText, remoteValue.getType(), remoteValue.getObjectId(), false); + } } }