mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-31 12:24:10 -08:00
Wasm: fix issues with debugger
This commit is contained in:
parent
a6add26aaa
commit
313e4ed87f
|
@ -59,8 +59,8 @@ public class LineInfoUnpackedSequence {
|
||||||
}
|
}
|
||||||
var index = CollectionUtil.binarySearch(locations, address, InstructionLocation::address);
|
var index = CollectionUtil.binarySearch(locations, address, InstructionLocation::address);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = -index;
|
index = -index - 2;
|
||||||
}
|
}
|
||||||
return Math.min(locations.size() - 1, index);
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,9 @@ package org.teavm.backend.wasm.debug.info;
|
||||||
import com.carrotsearch.hppc.IntArrayDeque;
|
import com.carrotsearch.hppc.IntArrayDeque;
|
||||||
import com.carrotsearch.hppc.IntHashSet;
|
import com.carrotsearch.hppc.IntHashSet;
|
||||||
import com.carrotsearch.hppc.IntSet;
|
import com.carrotsearch.hppc.IntSet;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.teavm.backend.wasm.debug.parser.DebugInfoParser;
|
|
||||||
import org.teavm.common.ByteArrayAsyncInputStream;
|
|
||||||
import org.teavm.common.CollectionUtil;
|
import org.teavm.common.CollectionUtil;
|
||||||
|
|
||||||
public class StepLocationsFinder {
|
public class StepLocationsFinder {
|
||||||
|
@ -208,16 +203,4 @@ public class StepLocationsFinder {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
|
||||||
var file = new File("/home/konsoletyper/prog/apache-tomcat-10.0.4/webapps/wasm/classes.wasm");
|
|
||||||
var input = new ByteArrayAsyncInputStream(Files.readAllBytes(file.toPath()));
|
|
||||||
var parser = new DebugInfoParser(input);
|
|
||||||
input.readFully(parser::parse);
|
|
||||||
var debugInfo = parser.getDebugInfo();
|
|
||||||
|
|
||||||
var finder = new StepLocationsFinder(debugInfo);
|
|
||||||
finder.step("org/teavm/samples/wasi/WasiTest2.java", 9, 0x943e + debugInfo.offset(), false);
|
|
||||||
System.out.println(Arrays.toString(finder.getBreakpointAddresses()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class ControlFlowParser implements CodeSectionListener, CodeListener, Add
|
||||||
var token = blocks.size();
|
var token = blocks.size();
|
||||||
var branch = !loop ? newPendingBranch(false) : null;
|
var branch = !loop ? newPendingBranch(false) : null;
|
||||||
var block = new Block(branch, address);
|
var block = new Block(branch, address);
|
||||||
|
block.loop = loop;
|
||||||
blocks.add(block);
|
blocks.add(block);
|
||||||
if (branch != null) {
|
if (branch != null) {
|
||||||
block.pendingBranches.add(branch);
|
block.pendingBranches.add(branch);
|
||||||
|
@ -135,17 +136,16 @@ public class ControlFlowParser implements CodeSectionListener, CodeListener, Add
|
||||||
if (opcode == BranchOpcode.BR_IF) {
|
if (opcode == BranchOpcode.BR_IF) {
|
||||||
pendingBranches.add(branch);
|
pendingBranches.add(branch);
|
||||||
}
|
}
|
||||||
var block = blocks.get(target);
|
branch.jumpTo(blocks.get(target));
|
||||||
block.pendingBranches.add(branch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tableBranch(int[] depths, int[] targets, int defaultDepth, int defaultTarget) {
|
public void tableBranch(int[] depths, int[] targets, int defaultDepth, int defaultTarget) {
|
||||||
var branch = newPendingBranch(false);
|
var branch = newPendingBranch(false);
|
||||||
for (var target : targets) {
|
for (var target : targets) {
|
||||||
blocks.get(target).pendingBranches.add(branch);
|
branch.jumpTo(blocks.get(target));
|
||||||
}
|
}
|
||||||
blocks.get(defaultTarget).pendingBranches.add(branch);
|
branch.jumpTo(blocks.get(defaultDepth));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Branch newPendingBranch(boolean isCall) {
|
private Branch newPendingBranch(boolean isCall) {
|
||||||
|
@ -185,6 +185,7 @@ public class ControlFlowParser implements CodeSectionListener, CodeListener, Add
|
||||||
|
|
||||||
private static class Block {
|
private static class Block {
|
||||||
Branch branch;
|
Branch branch;
|
||||||
|
boolean loop;
|
||||||
final int address;
|
final int address;
|
||||||
List<Branch> pendingBranches = new ArrayList<>();
|
List<Branch> pendingBranches = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -203,5 +204,13 @@ public class ControlFlowParser implements CodeSectionListener, CodeListener, Add
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.isCall = isCall;
|
this.isCall = isCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void jumpTo(Block block) {
|
||||||
|
if (block.loop) {
|
||||||
|
targets.add(block.address);
|
||||||
|
} else {
|
||||||
|
block.pendingBranches.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1463,26 +1463,40 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
|
||||||
WasmIntBinary binary = (WasmIntBinary) expr;
|
WasmIntBinary binary = (WasmIntBinary) expr;
|
||||||
if (binary.getType() == WasmIntType.INT32 && binary.getOperation() == WasmIntBinaryOperation.XOR) {
|
if (binary.getType() == WasmIntType.INT32 && binary.getOperation() == WasmIntBinaryOperation.XOR) {
|
||||||
if (isOne(binary.getFirst())) {
|
if (isOne(binary.getFirst())) {
|
||||||
return binary.getSecond();
|
var result = binary.getSecond();
|
||||||
|
if (result.getLocation() == null && expr.getLocation() != null) {
|
||||||
|
result.setLocation(expr.getLocation());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (isOne(binary.getSecond())) {
|
if (isOne(binary.getSecond())) {
|
||||||
return binary.getFirst();
|
var result = binary.getFirst();
|
||||||
|
if (result.getLocation() == null && expr.getLocation() != null) {
|
||||||
|
result.setLocation(expr.getLocation());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WasmIntBinaryOperation negatedOp = negate(binary.getOperation());
|
WasmIntBinaryOperation negatedOp = negate(binary.getOperation());
|
||||||
if (negatedOp != null) {
|
if (negatedOp != null) {
|
||||||
return new WasmIntBinary(binary.getType(), negatedOp, binary.getFirst(), binary.getSecond());
|
var result = new WasmIntBinary(binary.getType(), negatedOp, binary.getFirst(), binary.getSecond());
|
||||||
|
result.setLocation(expr.getLocation());
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
} else if (expr instanceof WasmFloatBinary) {
|
} else if (expr instanceof WasmFloatBinary) {
|
||||||
WasmFloatBinary binary = (WasmFloatBinary) expr;
|
WasmFloatBinary binary = (WasmFloatBinary) expr;
|
||||||
WasmFloatBinaryOperation negatedOp = negate(binary.getOperation());
|
WasmFloatBinaryOperation negatedOp = negate(binary.getOperation());
|
||||||
if (negatedOp != null) {
|
if (negatedOp != null) {
|
||||||
return new WasmFloatBinary(binary.getType(), negatedOp, binary.getFirst(), binary.getSecond());
|
var result = new WasmFloatBinary(binary.getType(), negatedOp, binary.getFirst(), binary.getSecond());
|
||||||
|
result.setLocation(expr.getLocation());
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, expr, new WasmInt32Constant(0));
|
var result = new WasmIntBinary(WasmIntType.INT32, WasmIntBinaryOperation.EQ, expr, new WasmInt32Constant(0));
|
||||||
|
result.setLocation(expr.getLocation());
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isOne(WasmExpression expression) {
|
private static boolean isOne(WasmExpression expression) {
|
||||||
|
|
|
@ -86,6 +86,7 @@ public class ChromeRDPDebugger extends BaseChromeRDPDebugger implements JavaScri
|
||||||
protected void onDetach() {
|
protected void onDetach() {
|
||||||
suspended = false;
|
suspended = false;
|
||||||
callStack = null;
|
callStack = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Promise<Void> injectFunctions(int contextId) {
|
private Promise<Void> injectFunctions(int contextId) {
|
||||||
|
@ -119,6 +120,7 @@ public class ChromeRDPDebugger extends BaseChromeRDPDebugger implements JavaScri
|
||||||
protected Promise<Void> handleMessage(Message message) throws IOException {
|
protected Promise<Void> handleMessage(Message message) throws IOException {
|
||||||
switch (message.getMethod()) {
|
switch (message.getMethod()) {
|
||||||
case "TeaVM.ping":
|
case "TeaVM.ping":
|
||||||
|
sendPong();
|
||||||
return Promise.VOID;
|
return Promise.VOID;
|
||||||
case "Debugger.paused":
|
case "Debugger.paused":
|
||||||
return firePaused(parseJson(SuspendedNotification.class, message.getParams()));
|
return firePaused(parseJson(SuspendedNotification.class, message.getParams()));
|
||||||
|
@ -130,6 +132,12 @@ public class ChromeRDPDebugger extends BaseChromeRDPDebugger implements JavaScri
|
||||||
return Promise.VOID;
|
return Promise.VOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPong() {
|
||||||
|
var message = new Message();
|
||||||
|
message.setMethod("TeaVM.pong");
|
||||||
|
sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
private Promise<Void> firePaused(SuspendedNotification params) {
|
private Promise<Void> firePaused(SuspendedNotification params) {
|
||||||
suspended = true;
|
suspended = true;
|
||||||
CallFrameDTO[] callFrameDTOs = params.getCallFrames();
|
CallFrameDTO[] callFrameDTOs = params.getCallFrames();
|
||||||
|
|
|
@ -90,6 +90,7 @@ public final class ChromeRDPRunner {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void detached() {
|
public void detached() {
|
||||||
|
queue.offer(() -> { });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -121,6 +122,7 @@ public final class ChromeRDPRunner {
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
} else if (!debugger.isAttached() && wasAttached) {
|
} else if (!debugger.isAttached() && wasAttached) {
|
||||||
|
System.out.println("Detached");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,20 +45,32 @@ class DebuggerAgent {
|
||||||
this.sendMessage(pendingMessage);
|
this.sendMessage(pendingMessage);
|
||||||
}
|
}
|
||||||
this.pendingMessages = null;
|
this.pendingMessages = null;
|
||||||
this.pingTimeout = setInterval(() => {
|
this.sendPing();
|
||||||
this.sendMessage({ method: "TeaVM.ping" });
|
|
||||||
}, 2000);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendPing() {
|
||||||
|
this.sendMessage({ method: "TeaVM.ping" });
|
||||||
|
}
|
||||||
|
|
||||||
|
schedulePing() {
|
||||||
|
this.pingTimeout = setTimeout(() => {
|
||||||
|
this.sendPing();
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
stopPing() {
|
stopPing() {
|
||||||
if (this.pingTimeout != null) {
|
if (this.pingTimeout != null) {
|
||||||
clearInterval(this.pingTimeout);
|
clearTimeout(this.pingTimeout);
|
||||||
this.pingTimeout = null;
|
this.pingTimeout = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
receiveMessage(message) {
|
receiveMessage(message) {
|
||||||
|
if (message.method === "TeaVM.pong") {
|
||||||
|
this.schedulePing();
|
||||||
|
return;
|
||||||
|
}
|
||||||
chrome.debugger.sendCommand(this.debuggee, message.method, message.params, response => {
|
chrome.debugger.sendCommand(this.debuggee, message.method, message.params, response => {
|
||||||
if (message.id) {
|
if (message.id) {
|
||||||
const responseToServer = {
|
const responseToServer = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user