mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-27 01:30:35 +08:00
wasm gc: fix inlining support in debug info builder, fix support of debug info in disassembler
This commit is contained in:
parent
c2eb11e056
commit
f95250ddf7
@ -28,6 +28,7 @@ public class DebugLinesBuilder extends DebugSectionBuilder implements DebugLines
|
||||
private String file;
|
||||
private int line = 1;
|
||||
private Deque<State> states = new ArrayDeque<>();
|
||||
private StringBuilder indent = new StringBuilder(" ");
|
||||
|
||||
public DebugLinesBuilder(DebugFiles files, DebugMethods methods) {
|
||||
super(DebugConstants.SECTION_LINES);
|
||||
@ -47,6 +48,7 @@ public class DebugLinesBuilder extends DebugSectionBuilder implements DebugLines
|
||||
public void location(String file, int line) {
|
||||
if (Objects.equals(file, this.file) && this.ptr != lastWrittenPtr && this.line != line) {
|
||||
if (this.ptr - lastWrittenPtr < 32 && Math.abs(line - this.line) <= 3) {
|
||||
System.out.println(blob.ptr() + indent.toString() + "[user] ptr: " + this.ptr + ", line: " + line);
|
||||
blob.writeByte(DebugConstants.LOC_USER + (this.ptr - lastWrittenPtr) + 32 * (line - this.line + 3));
|
||||
this.line = line;
|
||||
lastWrittenPtr = ptr;
|
||||
@ -57,10 +59,12 @@ public class DebugLinesBuilder extends DebugSectionBuilder implements DebugLines
|
||||
flushPtr();
|
||||
this.line = 1;
|
||||
this.file = file;
|
||||
System.out.println(blob.ptr() + indent.toString() + "[file] " + file);
|
||||
blob.writeByte(DebugConstants.LOC_FILE).writeLEB(file != null ? files.filePtr(file) : 0);
|
||||
}
|
||||
if (this.line != line) {
|
||||
flushPtr();
|
||||
System.out.println(blob.ptr() + indent.toString() + "[line] " + line);
|
||||
blob.writeByte(DebugConstants.LOC_LINE).writeSLEB(line - this.line);
|
||||
this.line = line;
|
||||
}
|
||||
@ -73,6 +77,7 @@ public class DebugLinesBuilder extends DebugSectionBuilder implements DebugLines
|
||||
|
||||
private void flushPtr() {
|
||||
if (ptr != lastWrittenPtr) {
|
||||
System.out.println(blob.ptr() + indent.toString() + "[ptr] " + ptr);
|
||||
blob.writeLEB(DebugConstants.LOC_PTR);
|
||||
blob.writeLEB(ptr - lastWrittenPtr);
|
||||
lastWrittenPtr = ptr;
|
||||
@ -82,6 +87,8 @@ public class DebugLinesBuilder extends DebugSectionBuilder implements DebugLines
|
||||
@Override
|
||||
public void start(MethodReference methodReference) {
|
||||
flushPtr();
|
||||
System.out.println(blob.ptr() + indent.toString() + "[start] method: " + methodReference);
|
||||
indent.append(".");
|
||||
blob.writeLEB(DebugConstants.LOC_START);
|
||||
blob.writeLEB(methods.methodPtr(methodReference));
|
||||
states.push(new State(file, line));
|
||||
@ -92,6 +99,8 @@ public class DebugLinesBuilder extends DebugSectionBuilder implements DebugLines
|
||||
@Override
|
||||
public void end() {
|
||||
flushPtr();
|
||||
indent.setLength(indent.length() - 1);
|
||||
System.out.println(blob.ptr() + indent.toString() + "[end]");
|
||||
blob.writeLEB(DebugConstants.LOC_END);
|
||||
if (!states.isEmpty()) {
|
||||
var state = states.pop();
|
||||
|
@ -104,16 +104,15 @@ public abstract class DisassemblyWriter {
|
||||
if (currentSequenceIndex >= debugLines.sequences().size()) {
|
||||
return;
|
||||
}
|
||||
var force = false;
|
||||
if (currentCommandIndex < 0) {
|
||||
if (addressWithinSection < debugLines.sequences().get(currentSequenceIndex).startAddress()) {
|
||||
return;
|
||||
}
|
||||
currentCommandIndex = 0;
|
||||
force = true;
|
||||
printSingleDebugAnnotation("start debug line sequence");
|
||||
} else {
|
||||
if (addressWithinSection >= debugLines.sequences().get(currentSequenceIndex).endAddress()) {
|
||||
printSingleDebugAnnotation("<end debug line sequence>");
|
||||
printSingleDebugAnnotation("end debug line sequence");
|
||||
++currentSequenceIndex;
|
||||
currentCommandIndex = -1;
|
||||
lineInfoIndent = 0;
|
||||
@ -122,45 +121,42 @@ public abstract class DisassemblyWriter {
|
||||
}
|
||||
|
||||
var sequence = debugLines.sequences().get(currentSequenceIndex);
|
||||
if (currentCommandIndex >= sequence.commands().size()) {
|
||||
return;
|
||||
}
|
||||
var command = sequence.commands().get(currentCommandIndex);
|
||||
if (!force) {
|
||||
if (currentCommandIndex + 1 < sequence.commands().size()
|
||||
&& addressWithinSection >= sequence.commands().get(currentCommandIndex + 1).address()) {
|
||||
command = sequence.commands().get(++currentCommandIndex);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
command.acceptVisitor(new LineInfoCommandVisitor() {
|
||||
@Override
|
||||
public void visit(LineInfoEnterCommand command) {
|
||||
printSingleDebugAnnotation(" at " + command.method().fullName());
|
||||
++lineInfoIndent;
|
||||
while (currentCommandIndex < sequence.commands().size()) {
|
||||
var command = sequence.commands().get(currentCommandIndex);
|
||||
if (addressWithinSection < command.address()) {
|
||||
break;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LineInfoExitCommand command) {
|
||||
--lineInfoIndent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LineInfoFileCommand command) {
|
||||
if (command.file() == null) {
|
||||
printSingleDebugAnnotation("at <unknown>:" + command.line());
|
||||
} else {
|
||||
printSingleDebugAnnotation(" at " + command.file().name() + ":" + command.line());
|
||||
command.acceptVisitor(new LineInfoCommandVisitor() {
|
||||
@Override
|
||||
public void visit(LineInfoEnterCommand command) {
|
||||
printSingleDebugAnnotation("enter inline " + command.method().cls().name() + "."
|
||||
+ command.method().name());
|
||||
++lineInfoIndent;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LineInfoLineCommand command) {
|
||||
printSingleDebugAnnotation(" at " + command.line());
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void visit(LineInfoExitCommand command) {
|
||||
--lineInfoIndent;
|
||||
printSingleDebugAnnotation("exit inline");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LineInfoFileCommand command) {
|
||||
if (command.file() == null) {
|
||||
printSingleDebugAnnotation("at <unknown>:" + command.line());
|
||||
} else {
|
||||
printSingleDebugAnnotation("at " + command.file().name() + ":" + command.line());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LineInfoLineCommand command) {
|
||||
printSingleDebugAnnotation("at " + command.line());
|
||||
}
|
||||
});
|
||||
++currentCommandIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private void printSingleDebugAnnotation(String text) {
|
||||
@ -172,7 +168,7 @@ public abstract class DisassemblyWriter {
|
||||
out.print(" ");
|
||||
}
|
||||
startAnnotation();
|
||||
out.print("(;");
|
||||
out.print("(; ");
|
||||
write(text);
|
||||
out.print(" ;)");
|
||||
endAnnotation();
|
||||
|
@ -1405,6 +1405,10 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||
flushLocation();
|
||||
if (debugLines != null) {
|
||||
debugLines.advance(writer.getPosition() + addressOffset);
|
||||
while (!methodStack.isEmpty()) {
|
||||
methodStack.removeLast();
|
||||
debugLines.end();
|
||||
}
|
||||
debugLines.end();
|
||||
}
|
||||
}
|
||||
@ -1433,7 +1437,7 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
|
||||
var loc = textLocationToEmit;
|
||||
var inlining = loc != null ? loc.getInlining() : null;
|
||||
while (inlining != null) {
|
||||
currentMethodStack.add(loc.getInlining().getMethod());
|
||||
currentMethodStack.add(inlining.getMethod());
|
||||
inlining = inlining.getParent();
|
||||
}
|
||||
Collections.reverse(currentMethodStack);
|
||||
|
Loading…
Reference in New Issue
Block a user