mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 08:24:10 -08:00
Adds call sites to debug information
This commit is contained in:
parent
497d2424bb
commit
7153a8e2c9
|
@ -39,11 +39,14 @@ public class DebugInformation {
|
||||||
Map<String, Integer> methodMap;
|
Map<String, Integer> methodMap;
|
||||||
String[] variableNames;
|
String[] variableNames;
|
||||||
Map<String, Integer> variableNameMap;
|
Map<String, Integer> variableNameMap;
|
||||||
|
long[] exactMethods;
|
||||||
|
Map<Long, Integer> exactMethodMap;
|
||||||
FileDescription[] fileDescriptions;
|
FileDescription[] fileDescriptions;
|
||||||
Mapping fileMapping;
|
Mapping fileMapping;
|
||||||
Mapping classMapping;
|
Mapping classMapping;
|
||||||
Mapping methodMapping;
|
Mapping methodMapping;
|
||||||
Mapping lineMapping;
|
Mapping lineMapping;
|
||||||
|
Mapping callSiteMapping;
|
||||||
MultiMapping[] variableMappings;
|
MultiMapping[] variableMappings;
|
||||||
CFG[] controlFlowGraphs;
|
CFG[] controlFlowGraphs;
|
||||||
List<ClassMetadata> classesMetadata;
|
List<ClassMetadata> classesMetadata;
|
||||||
|
@ -170,6 +173,25 @@ public class DebugInformation {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MethodReference getCallSite(GeneratedLocation location) {
|
||||||
|
int keyIndex = indexByKey(callSiteMapping, location);
|
||||||
|
if (keyIndex < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int valueIndex = callSiteMapping.values[keyIndex];
|
||||||
|
if (valueIndex < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
long item = exactMethods[valueIndex];
|
||||||
|
int classIndex = (int)(item >> 32);
|
||||||
|
int methodIndex = (int)item;
|
||||||
|
return new MethodReference(classNames[classIndex], MethodDescriptor.parse(methods[methodIndex]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public MethodReference getCallSite(int line, int column) {
|
||||||
|
return getCallSite(new GeneratedLocation(line, column));
|
||||||
|
}
|
||||||
|
|
||||||
private <T> T componentByKey(Mapping mapping, T[] values, GeneratedLocation location) {
|
private <T> T componentByKey(Mapping mapping, T[] values, GeneratedLocation location) {
|
||||||
int keyIndex = indexByKey(mapping, location);
|
int keyIndex = indexByKey(mapping, location);
|
||||||
int valueIndex = keyIndex >= 0 ? mapping.values[keyIndex] : -1;
|
int valueIndex = keyIndex >= 0 ? mapping.values[keyIndex] : -1;
|
||||||
|
@ -216,6 +238,10 @@ public class DebugInformation {
|
||||||
fieldMap = mapArray(fields);
|
fieldMap = mapArray(fields);
|
||||||
methodMap = mapArray(methods);
|
methodMap = mapArray(methods);
|
||||||
variableNameMap = mapArray(variableNames);
|
variableNameMap = mapArray(variableNames);
|
||||||
|
exactMethodMap = new HashMap<>();
|
||||||
|
for (int i = 0; i < exactMethods.length; ++i) {
|
||||||
|
exactMethodMap.put(exactMethods[i], i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Integer> mapArray(String[] array) {
|
private Map<String, Integer> mapArray(String[] array) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.*;
|
||||||
import org.teavm.codegen.LocationProvider;
|
import org.teavm.codegen.LocationProvider;
|
||||||
import org.teavm.common.IntegerArray;
|
import org.teavm.common.IntegerArray;
|
||||||
import org.teavm.model.MethodDescriptor;
|
import org.teavm.model.MethodDescriptor;
|
||||||
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -32,10 +33,13 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
|
||||||
private MappedList fields = new MappedList();
|
private MappedList fields = new MappedList();
|
||||||
private MappedList methods = new MappedList();
|
private MappedList methods = new MappedList();
|
||||||
private MappedList variableNames = new MappedList();
|
private MappedList variableNames = new MappedList();
|
||||||
|
private List<Long> exactMethods = new ArrayList<>();
|
||||||
|
private Map<Long, Integer> exactMethodMap = new HashMap<>();
|
||||||
private Mapping fileMapping = new Mapping();
|
private Mapping fileMapping = new Mapping();
|
||||||
private Mapping lineMapping = new Mapping();
|
private Mapping lineMapping = new Mapping();
|
||||||
private Mapping classMapping = new Mapping();
|
private Mapping classMapping = new Mapping();
|
||||||
private Mapping methodMapping = new Mapping();
|
private Mapping methodMapping = new Mapping();
|
||||||
|
private Mapping callSiteMapping = new Mapping();
|
||||||
private Map<Integer, MultiMapping> variableMappings = new HashMap<>();
|
private Map<Integer, MultiMapping> variableMappings = new HashMap<>();
|
||||||
private MethodDescriptor currentMethod;
|
private MethodDescriptor currentMethod;
|
||||||
private String currentClass;
|
private String currentClass;
|
||||||
|
@ -104,6 +108,24 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
|
||||||
mapping.add(locationProvider, sourceIndexes);
|
mapping.add(locationProvider, sourceIndexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void emitCallSite(MethodReference method) {
|
||||||
|
if (method != null) {
|
||||||
|
int methodIndex = methods.index(method.getDescriptor().toString());
|
||||||
|
int classIndex = classes.index(method.getClassName());
|
||||||
|
long fullIndex = (((long)classIndex << 32) | methodIndex) + 1;
|
||||||
|
Integer exactMethodIndex = exactMethodMap.get(fullIndex);
|
||||||
|
if (exactMethodIndex == null) {
|
||||||
|
exactMethodIndex = exactMethods.size();
|
||||||
|
exactMethodMap.put(fullIndex, exactMethodIndex);
|
||||||
|
exactMethods.add(fullIndex);
|
||||||
|
}
|
||||||
|
callSiteMapping.add(locationProvider, exactMethodIndex);
|
||||||
|
} else {
|
||||||
|
callSiteMapping.add(locationProvider, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addClass(String className, String parentName) {
|
public void addClass(String className, String parentName) {
|
||||||
int classIndex = classes.index(className);
|
int classIndex = classes.index(className);
|
||||||
|
@ -152,11 +174,17 @@ public class DebugInformationBuilder implements DebugInformationEmitter {
|
||||||
debugInformation.fields = fields.getItems();
|
debugInformation.fields = fields.getItems();
|
||||||
debugInformation.methods = methods.getItems();
|
debugInformation.methods = methods.getItems();
|
||||||
debugInformation.variableNames = variableNames.getItems();
|
debugInformation.variableNames = variableNames.getItems();
|
||||||
|
debugInformation.exactMethods = new long[exactMethods.size()];
|
||||||
|
for (int i = 0; i < exactMethods.size(); ++i) {
|
||||||
|
debugInformation.exactMethods[i] = exactMethods.get(i);
|
||||||
|
}
|
||||||
|
debugInformation.exactMethodMap = new HashMap<>(exactMethodMap);
|
||||||
|
|
||||||
debugInformation.fileMapping = fileMapping.build();
|
debugInformation.fileMapping = fileMapping.build();
|
||||||
debugInformation.lineMapping = lineMapping.build();
|
debugInformation.lineMapping = lineMapping.build();
|
||||||
debugInformation.classMapping = classMapping.build();
|
debugInformation.classMapping = classMapping.build();
|
||||||
debugInformation.methodMapping = methodMapping.build();
|
debugInformation.methodMapping = methodMapping.build();
|
||||||
|
debugInformation.callSiteMapping = callSiteMapping.build();
|
||||||
debugInformation.variableMappings = new DebugInformation.MultiMapping[variableNames.list.size()];
|
debugInformation.variableMappings = new DebugInformation.MultiMapping[variableNames.list.size()];
|
||||||
for (int var : variableMappings.keySet()) {
|
for (int var : variableMappings.keySet()) {
|
||||||
MultiMapping mapping = variableMappings.get(var);
|
MultiMapping mapping = variableMappings.get(var);
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.debugging;
|
||||||
|
|
||||||
import org.teavm.codegen.LocationProvider;
|
import org.teavm.codegen.LocationProvider;
|
||||||
import org.teavm.model.MethodDescriptor;
|
import org.teavm.model.MethodDescriptor;
|
||||||
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -33,6 +34,8 @@ public interface DebugInformationEmitter {
|
||||||
|
|
||||||
void emitVariable(String[] sourceNames, String generatedName);
|
void emitVariable(String[] sourceNames, String generatedName);
|
||||||
|
|
||||||
|
void emitCallSite(MethodReference method);
|
||||||
|
|
||||||
void addClass(String className, String parentName);
|
void addClass(String className, String parentName);
|
||||||
|
|
||||||
void addField(String fieldName, String jsName);
|
void addField(String fieldName, String jsName);
|
||||||
|
|
|
@ -41,10 +41,12 @@ class DebugInformationReader {
|
||||||
debugInfo.fields = readStrings();
|
debugInfo.fields = readStrings();
|
||||||
debugInfo.methods = readStrings();
|
debugInfo.methods = readStrings();
|
||||||
debugInfo.variableNames = readStrings();
|
debugInfo.variableNames = readStrings();
|
||||||
|
debugInfo.exactMethods = readExactMethods();
|
||||||
debugInfo.fileMapping = readMapping();
|
debugInfo.fileMapping = readMapping();
|
||||||
debugInfo.lineMapping = readMapping();
|
debugInfo.lineMapping = readMapping();
|
||||||
debugInfo.classMapping = readMapping();
|
debugInfo.classMapping = readMapping();
|
||||||
debugInfo.methodMapping = readMapping();
|
debugInfo.methodMapping = readMapping();
|
||||||
|
debugInfo.callSiteMapping = readMapping();
|
||||||
debugInfo.variableMappings = readVariableMappings(debugInfo.variableNames.length);
|
debugInfo.variableMappings = readVariableMappings(debugInfo.variableNames.length);
|
||||||
debugInfo.classesMetadata = readClassesMetadata(debugInfo.classNames.length);
|
debugInfo.classesMetadata = readClassesMetadata(debugInfo.classNames.length);
|
||||||
debugInfo.controlFlowGraphs = readCFGs(debugInfo.fileNames.length);
|
debugInfo.controlFlowGraphs = readCFGs(debugInfo.fileNames.length);
|
||||||
|
@ -185,6 +187,18 @@ class DebugInformationReader {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long[] readExactMethods() throws IOException {
|
||||||
|
long[] result = new long[readUnsignedNumber()];
|
||||||
|
int lastClass = 0;
|
||||||
|
int lastMethod = 0;
|
||||||
|
for (int i = 0; i < result.length; ++i) {
|
||||||
|
lastClass += readNumber();
|
||||||
|
lastMethod += readNumber();
|
||||||
|
result[i] = ((long)lastClass << 32) | lastMethod;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private int[] readRle() throws IOException {
|
private int[] readRle() throws IOException {
|
||||||
int[] array = new int[readUnsignedNumber()];
|
int[] array = new int[readUnsignedNumber()];
|
||||||
for (int i = 0; i < array.length;) {
|
for (int i = 0; i < array.length;) {
|
||||||
|
|
|
@ -41,11 +41,13 @@ class DebugInformationWriter {
|
||||||
writeStringArray(debugInfo.fields);
|
writeStringArray(debugInfo.fields);
|
||||||
writeStringArray(debugInfo.methods);
|
writeStringArray(debugInfo.methods);
|
||||||
writeStringArray(debugInfo.variableNames);
|
writeStringArray(debugInfo.variableNames);
|
||||||
|
writeExactMethods(debugInfo.exactMethods);
|
||||||
|
|
||||||
writeMapping(debugInfo.fileMapping);
|
writeMapping(debugInfo.fileMapping);
|
||||||
writeMapping(debugInfo.lineMapping);
|
writeMapping(debugInfo.lineMapping);
|
||||||
writeMapping(debugInfo.classMapping);
|
writeMapping(debugInfo.classMapping);
|
||||||
writeMapping(debugInfo.methodMapping);
|
writeMapping(debugInfo.methodMapping);
|
||||||
|
writeMapping(debugInfo.callSiteMapping);
|
||||||
writeVariableMappings(debugInfo);
|
writeVariableMappings(debugInfo);
|
||||||
writeClassMetadata(debugInfo.classesMetadata);
|
writeClassMetadata(debugInfo.classesMetadata);
|
||||||
writeCFGs(debugInfo);
|
writeCFGs(debugInfo);
|
||||||
|
@ -97,6 +99,21 @@ class DebugInformationWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeExactMethods(long[] array) throws IOException {
|
||||||
|
int lastClass = 0;
|
||||||
|
int lastMethod = 0;
|
||||||
|
writeUnsignedNumber(array.length);
|
||||||
|
for (int i = 0; i < array.length; ++i) {
|
||||||
|
long item = array[i];
|
||||||
|
int classIndex = (int)(item >> 32);
|
||||||
|
int methodIndex = (int)item;
|
||||||
|
writeNumber(classIndex - lastClass);
|
||||||
|
lastClass = classIndex;
|
||||||
|
writeNumber(methodIndex - lastMethod);
|
||||||
|
lastMethod = methodIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void writeMapping(DebugInformation.MultiMapping mapping) throws IOException {
|
private void writeMapping(DebugInformation.MultiMapping mapping) throws IOException {
|
||||||
int[] lines = mapping.lines.clone();
|
int[] lines = mapping.lines.clone();
|
||||||
int last = 0;
|
int last = 0;
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.teavm.debugging;
|
||||||
|
|
||||||
import org.teavm.codegen.LocationProvider;
|
import org.teavm.codegen.LocationProvider;
|
||||||
import org.teavm.model.MethodDescriptor;
|
import org.teavm.model.MethodDescriptor;
|
||||||
|
import org.teavm.model.MethodReference;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +41,10 @@ public class DummyDebugInformationEmitter implements DebugInformationEmitter {
|
||||||
public void emitVariable(String[] sourceName, String generatedName) {
|
public void emitVariable(String[] sourceName, String generatedName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void emitCallSite(MethodReference method) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLocationProvider(LocationProvider locationProvider) {
|
public void setLocationProvider(LocationProvider locationProvider) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
private ServiceRepository services;
|
private ServiceRepository services;
|
||||||
private DebugInformationEmitter debugEmitter = new DummyDebugInformationEmitter();
|
private DebugInformationEmitter debugEmitter = new DummyDebugInformationEmitter();
|
||||||
private Deque<NodeLocation> locationStack = new ArrayDeque<>();
|
private Deque<NodeLocation> locationStack = new ArrayDeque<>();
|
||||||
|
private Deque<MethodReference> callSiteStack = new ArrayDeque<>();
|
||||||
|
|
||||||
private static class InjectorHolder {
|
private static class InjectorHolder {
|
||||||
public final Injector injector;
|
public final Injector injector;
|
||||||
|
@ -593,6 +594,17 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void pushCallSite(MethodReference method) {
|
||||||
|
callSiteStack.push(method);
|
||||||
|
debugEmitter.emitCallSite(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void popCallSite() {
|
||||||
|
callSiteStack.pop();
|
||||||
|
MethodReference method = callSiteStack.peek();
|
||||||
|
debugEmitter.emitCallSite(method);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(AssignmentStatement statement) throws RenderingException {
|
public void visit(AssignmentStatement statement) throws RenderingException {
|
||||||
try {
|
try {
|
||||||
|
@ -1284,6 +1296,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
if (expr.getLocation() != null) {
|
if (expr.getLocation() != null) {
|
||||||
pushLocation(expr.getLocation());
|
pushLocation(expr.getLocation());
|
||||||
}
|
}
|
||||||
|
pushCallSite(expr.getMethod());
|
||||||
Injector injector = getInjector(expr.getMethod());
|
Injector injector = getInjector(expr.getMethod());
|
||||||
if (injector != null) {
|
if (injector != null) {
|
||||||
injector.generate(new InjectorContextImpl(expr.getArguments()), expr.getMethod());
|
injector.generate(new InjectorContextImpl(expr.getArguments()), expr.getMethod());
|
||||||
|
@ -1334,6 +1347,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
popCallSite();
|
||||||
if (expr.getLocation() != null) {
|
if (expr.getLocation() != null) {
|
||||||
popLocation();
|
popLocation();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user