Wasm: fix issues in DWARF generator

This commit is contained in:
Alexey Andreev 2022-11-20 08:42:32 +01:00
parent 7f38697d50
commit 1399045ff6
4 changed files with 20 additions and 12 deletions

View File

@ -173,8 +173,8 @@ class DwarfLinesGenerator {
instructionsBlob.writeLEB(fileRef);
changed = true;
}
if (advanceTo(address, line)) {
changed = true;
if (line != this.line || this.address != address) {
changed = advanceTo(address, line);
}
if (changed) {
instructionsBlob.writeByte(DW_LNS_COPY);
@ -186,23 +186,23 @@ class DwarfLinesGenerator {
if (!sequenceStarted) {
return;
}
advanceTo(address, line);
if (this.address != address) {
advanceTo(address, line);
}
instructionsBlob.writeByte(0);
instructionsBlob.writeByte(1);
instructionsBlob.writeByte(DW_LNE_END_SEQUENCE);
this.line = 1;
this.file = 0;
this.file = 1;
this.address = 0;
sequenceStarted = false;
}
private boolean advanceTo(int address, int line) {
if (address == this.address && line == this.line) {
return false;
}
int lineIncrement = line - this.line;
int addressIncrement = address - this.address;
if (!tryEmitSpecial(lineIncrement, addressIncrement)) {
var result = !tryEmitSpecial(lineIncrement, addressIncrement);
if (result) {
if (lineIncrement != 0) {
instructionsBlob.writeByte(DW_LNS_ADVANCE_LINE);
instructionsBlob.writeSLEB(lineIncrement);
@ -214,7 +214,7 @@ class DwarfLinesGenerator {
}
this.line = line;
this.address = address;
return true;
return result;
}
private boolean tryEmitSpecial(int lineIncrement, int addressIncrement) {

View File

@ -903,21 +903,27 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
switch (expr.getMethod().getName()) {
case "allocStack":
generateAllocStack(expr.getArguments().get(0));
result.setLocation(expr.getLocation());
return;
case "releaseStack":
generateReleaseStack();
result.setLocation(expr.getLocation());
return;
case "registerGCRoot":
generateRegisterGcRoot(expr.getArguments().get(0), expr.getArguments().get(1));
result.setLocation(expr.getLocation());
return;
case "removeGCRoot":
generateRemoveGcRoot(expr.getArguments().get(0));
result.setLocation(expr.getLocation());
return;
case "registerCallSite":
generateRegisterCallSite(expr.getArguments().get(0));
result.setLocation(expr.getLocation());
return;
case "getExceptionHandlerId":
generateGetHandlerId();
result.setLocation(expr.getLocation());
return;
}
}
@ -941,6 +947,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor {
accept(argument);
call.getArguments().add(result);
}
call.setLocation(expr.getLocation());
result = call;
} else if (expr.getType() == InvocationType.CONSTRUCTOR) {
WasmBlock block = new WasmBlock(false);

View File

@ -331,8 +331,8 @@ public class WasmBinaryRenderer {
if (dwarfGenerator != null && function.getName() != null) {
infoWriter.tag(getMethodAbbrev());
infoWriter.writeInt(dwarfGenerator.strings.stringRef(function.getName()));
infoWriter.writeInt(offset - 4);
infoWriter.writeInt(offset + code.getPosition());
infoWriter.writeInt(offset);
infoWriter.writeInt(offset + code.getPosition() - 1);
infoWriter.emptyTag();
}

View File

@ -875,7 +875,8 @@ class WasmBinaryRenderingVisitor implements WasmExpressionVisitor {
}
private void emitLocation(WasmExpression expression) {
if (dwarfGenerator == null || expression.getLocation() == null) {
if (dwarfGenerator == null || expression.getLocation() == null
|| expression.getLocation().getFileName() == null) {
return;
}
dwarfGenerator.lineNumber(writer.getPosition() + addressOffset, expression.getLocation().getFileName(),