Skip to content

Commit

Permalink
kotlin improvements: debugger and compilation (MobiVM#349)
Browse files Browse the repository at this point in the history
* LLVM: line number info extended with column number (will be used to reference debug information)

* LLVM, debugger: debug information retrieved from object file renamed to have Dwarf* prefix. Just to make difference with all kinds of debug information

* * hooks updated to include PC as part of call stack (will be used to find offset from method start)

* Debugger: local variable resolution rework (work in progress):
 - for each instruction variable slice is generated (list of visible variables at this instruction)
 - variables are being resolved not by line number of call stack but by PC
 - for this special table of pc to method start is generated which point to variables visible at specific PC

* * removed exception and replaced with trace to log (in case RoboVM runs in debug mode) for case when type of local doesn't match debug information. its kotlin case

* * reverted commited by mistake debug configuration for VM libraries

* * debugger: added support for Kotlin SMAP
* debug locations that were throwing exceptions removed
* cleanup

* * always append to @llvm.used as array even if only element has to be added. as debug version of llvm has assertion that checks for array type and will crash

* * variable slicer reworked to ignore parameter information while resolving variables. As kotlin reuses arguments slots and this made mess. Now only relies on debug information provided in class file

* * fixed to support recent builds, don't build 32bit version for mac anymore

* * fixed instrumentation of instruction. hook has to be called before first instruction of line, not before last. othervise complex expressions will be half solved when BP reaches.

* * reworked emitting .spfpoffset for arm targets in the way to use two different symbols: one for saving offset and second for emitting it. otherwise it crashes on assert due symbol was used reason in debug builds
  • Loading branch information
dkimitsa authored and Tom-Ski committed Jul 11, 2019
1 parent 3087632 commit 8a1b02e
Show file tree
Hide file tree
Showing 34 changed files with 1,895 additions and 606 deletions.
15 changes: 13 additions & 2 deletions compiler/compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<dependency>
<groupId>com.mobidevelop.robovm</groupId>
<artifactId>robovm-soot</artifactId>
<version>2.5.0-5</version>
<version>2.5.0-6</version>
</dependency>
<dependency>
<groupId>com.mobidevelop.robovm</groupId>
Expand Down Expand Up @@ -121,8 +121,19 @@
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<optimize>true</optimize>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import org.robovm.compiler.llvm.Variable;
import org.robovm.compiler.llvm.VariableRef;
import org.robovm.compiler.plugin.CompilerPlugin;
import org.robovm.compiler.plugin.debug.DebugInformationTools;
import org.robovm.compiler.plugin.debug.DebuggerDebugObjectFileInfo;
import org.robovm.compiler.trampoline.Checkcast;
import org.robovm.compiler.trampoline.Instanceof;
import org.robovm.compiler.trampoline.Invoke;
Expand All @@ -84,7 +84,6 @@
import org.robovm.llvm.binding.CodeGenFileType;
import org.robovm.llvm.binding.CodeGenOptLevel;
import org.robovm.llvm.binding.RelocMode;
import org.robovm.llvm.debuginfo.DebugObjectFileInfo;
import soot.BooleanType;
import soot.ByteType;
import soot.CharType;
Expand Down Expand Up @@ -603,10 +602,10 @@ public int compare(LineInfo o1, LineInfo o2) {
private static ModuleBuilder buildDebugInfoData(Config config, Clazz clazz, ObjectFile objectFile) throws IOException {
ModuleBuilder debugInfoMb = null;

DebugObjectFileInfo debugInfo = clazz.getAttachment(DebugObjectFileInfo.class);
DebuggerDebugObjectFileInfo.RawData debugInfo = clazz.getAttachment(DebuggerDebugObjectFileInfo.RawData.class);
if (debugInfo != null) {
// read all binary data to file
byte[] debugDataBytes = DebugInformationTools.dumpDebugInfo(debugInfo);
byte[] debugDataBytes = DebuggerDebugObjectFileInfo.dumpDebugInfo(debugInfo);
String debugInfoSymbol = Symbols.debugInfoSymbol(clazz.getInternalName());
debugInfoMb = new ModuleBuilder();
Global debugInfoSymbolGlobal = new Global(debugInfoSymbol, new ByteArrayConstant(debugDataBytes), true);
Expand Down Expand Up @@ -650,20 +649,17 @@ private static ModuleBuilder buildDebugInfoData(Config config, Clazz clazz, Obje
}

// also need to add reference to @llvm.used otherwise linker will drop out this data as not used
// dkimitsa: always add it as array even if there is only one element as llvm.used is array of pointers
// and debug version of llvm will crash on assertion while validating type
Global usedGlobal;
if (usedGlobalValues.size() > 1) {
ArrayConstant usedValuesArr = new ArrayConstant(new ArrayType(usedGlobalValues.size(), Type.I8_PTR),
usedGlobalValues.toArray(new Value[usedGlobalValues.size()]));
usedGlobal = new Global("llvm.used", Linkage.appending, usedValuesArr, false, "llvm.metadata");
} else {
usedGlobal = new Global("llvm.used", Linkage.appending, new ConstantBitcast(debugInfoSymbolGlobal.ref(), Type.I8_PTR),
false, "llvm.metadata");
}
ArrayConstant usedValuesArr = new ArrayConstant(new ArrayType(usedGlobalValues.size(), Type.I8_PTR),
usedGlobalValues.toArray(new Value[usedGlobalValues.size()]));
usedGlobal = new Global("llvm.used", Linkage.appending, usedValuesArr, false, "llvm.metadata");
debugInfoMb.addGlobal(usedGlobal);

if (config.isDumpIntermediates()) {
File f = new File(config.getDebugInfoOFile(clazz).getAbsolutePath() + ".dump");
DebugInformationTools.dumpDebugInfoAsText(debugInfo, f);
DebuggerDebugObjectFileInfo.dumpDebugInfoAsText(debugInfo, f);
}
}

Expand Down
Loading

0 comments on commit 8a1b02e

Please sign in to comment.