mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fixes bugs in debug information generator and writer
This commit is contained in:
parent
94b9b001cd
commit
62281f696c
|
@ -39,6 +39,7 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
|
|||
return locationProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocationProvider(LocationProvider locationProvider) {
|
||||
this.locationProvider = locationProvider;
|
||||
}
|
||||
|
@ -114,8 +115,9 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
|
|||
fileDesc.methodMap = fileDescProto.methodMap.toArray(new MethodReference[0]);
|
||||
fileDesc.generatedLocations = new GeneratedLocation[fileDescProto.generatedLocations.size()][];
|
||||
for (int i = 0; i < fileDescProto.generatedLocations.size(); ++i) {
|
||||
fileDesc.generatedLocations[i] = fileDescProto.generatedLocations.get(index)
|
||||
.toArray(new GeneratedLocation[0]);
|
||||
List<GeneratedLocation> locations = fileDescProto.generatedLocations.get(index);
|
||||
fileDesc.generatedLocations[i] = locations != null ?
|
||||
locations.toArray(new GeneratedLocation[0]) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +134,10 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
|
|||
line - generatedLocations.size() + 1, null));
|
||||
}
|
||||
List<GeneratedLocation> existingLocations = generatedLocations.get(line);
|
||||
if (existingLocations == null) {
|
||||
existingLocations = new ArrayList<>();
|
||||
generatedLocations.set(line, existingLocations);
|
||||
}
|
||||
existingLocations.add(location);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.teavm.debugging;
|
||||
|
||||
import org.teavm.codegen.LocationProvider;
|
||||
import org.teavm.model.MethodReference;
|
||||
|
||||
/**
|
||||
|
@ -22,6 +23,8 @@ import org.teavm.model.MethodReference;
|
|||
* @author Alexey Andreev
|
||||
*/
|
||||
public interface DebugInformationEmitter {
|
||||
void setLocationProvider(LocationProvider locationProvider);
|
||||
|
||||
void emitLocation(String fileName, int line);
|
||||
|
||||
void emitMethod(MethodReference method);
|
||||
|
|
|
@ -110,7 +110,11 @@ class DebugInformationWriter {
|
|||
|
||||
private void writeNumber(int number) throws IOException {
|
||||
do {
|
||||
number = (number << 1) | (number >>> 31);
|
||||
if (number < 0) {
|
||||
number = (-number << 1) | 1;
|
||||
} else {
|
||||
number = number << 1;
|
||||
}
|
||||
byte b = (byte)(number & 0x7F);
|
||||
if ((number & 0xFFFFFF80) != 0) {
|
||||
b |= 0x80;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package org.teavm.debugging;
|
||||
|
||||
import org.teavm.codegen.LocationProvider;
|
||||
import org.teavm.model.MethodReference;
|
||||
|
||||
|
||||
|
@ -30,4 +31,8 @@ public class DummyDebugInformationEmitter implements DebugInformationEmitter {
|
|||
@Override
|
||||
public void emitMethod(MethodReference method) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocationProvider(LocationProvider locationProvider) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ public class Decompiler {
|
|||
InstructionLocation lastLocation = null;
|
||||
NodeLocation nodeLocation = null;
|
||||
for (Instruction insn : generator.currentBlock.getInstructions()) {
|
||||
if (lastLocation != insn.getLocation()) {
|
||||
if (insn.getLocation() != null && lastLocation != insn.getLocation()) {
|
||||
lastLocation = insn.getLocation();
|
||||
nodeLocation = new NodeLocation(lastLocation.getFileName(), lastLocation.getLine());
|
||||
}
|
||||
|
|
|
@ -172,7 +172,11 @@ public class BasicBlock implements BasicBlockReader {
|
|||
|
||||
@Override
|
||||
public void readInstruction(int index, InstructionReader reader) {
|
||||
instructions.get(index).acceptVisitor(new InstructionReadVisitor(reader));
|
||||
Instruction insn = instructions.get(index);
|
||||
if (insn.getLocation() != null) {
|
||||
reader.location(insn.getLocation());
|
||||
}
|
||||
insn.acceptVisitor(new InstructionReadVisitor(reader));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,8 +37,6 @@ public class InstructionStringifier implements InstructionReader {
|
|||
if (location != null) {
|
||||
sb.append("at " + (location.getFileName() != null ? location.getFileName() : "<unknown>") + ":" +
|
||||
(location.getLine() >= 0 ? String.valueOf(location.getLine()) : "<unknown>"));
|
||||
} else {
|
||||
sb.append("<unkwnown>");
|
||||
}
|
||||
this.location = location;
|
||||
}
|
||||
|
|
|
@ -351,6 +351,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
|||
if (debugEmitter != null) {
|
||||
renderer.setDebugEmitter(debugEmitter);
|
||||
}
|
||||
debugEmitter.setLocationProvider(sourceWriter);
|
||||
for (Map.Entry<MethodReference, Injector> entry : methodInjectors.entrySet()) {
|
||||
renderer.addInjector(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user