Skip to content

Commit 7c67eb6

Browse files
authored
Improve dwarf support (#14)
* Removed duplicated argument from InteractiveDebugger the config already contains the symbolic wdcli path * Dwarf sourcemaps use syntax highlighting based on the file extension * Try to load dwarf info if there is no .map in the start screen Also added macos build for dwarf-line-mapping. * Update dwarf-line-mapping-mac * Better error handling when MIO fails to get debug info
1 parent e93d014 commit 7c67eb6

5 files changed

Lines changed: 28 additions & 11 deletions

File tree

dwarf-line-mapping-mac

2.87 MB
Binary file not shown.

src/main/kotlin/be/ugent/topl/mio/Main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ fun main(args: Array<String>) {
8888
else
8989
FlatDarkLaf.setup()
9090
if (args.size == 2)
91-
InteractiveDebugger(connection, config.symbolicWdcliPath, sourceMapping, config = config)
91+
InteractiveDebugger(connection, sourceMapping, config = config)
9292
else
93-
InteractiveDebugger(connection, config.symbolicWdcliPath, sourceMapping, args[2], config = config)
93+
InteractiveDebugger(connection, sourceMapping, args[2], config = config)
9494
}
9595
"repl" -> {
9696
val connection =

src/main/kotlin/be/ugent/topl/mio/sourcemap/DwarfSourceMap.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package be.ugent.topl.mio.sourcemap
22

33
import com.fasterxml.jackson.databind.ObjectMapper
44
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
5+
import com.formdev.flatlaf.util.SystemInfo
56
import org.fife.ui.rsyntaxtextarea.SyntaxConstants
67
import java.io.BufferedReader
78
import java.io.File
@@ -13,6 +14,8 @@ class DwarfSourceMap(
1314
private val pcToSource: Map<Int, DwarfLineMapping>,
1415
private val sourceToPc: Map<Pair<String, Int>, DwarfLineMapping>
1516
): SourceMap {
17+
private var mostRecentFile = getSourceFile(0)
18+
1619
override fun getLineForPc(pc: Int): Int {
1720
return pcToSource[pc]?.row ?: throw RuntimeException("No mapping for this pc")
1821
}
@@ -29,17 +32,24 @@ class DwarfSourceMap(
2932
}
3033

3134
override fun getSourceFileName(pc: Int): String {
32-
return pcToSource[pc]!!.file
35+
mostRecentFile = pcToSource[pc]!!.file
36+
return mostRecentFile
3337
}
3438

3539
override fun getStyle(): String {
36-
return SyntaxConstants.SYNTAX_STYLE_RUST
40+
return when {
41+
mostRecentFile.endsWith(".c") -> SyntaxConstants.SYNTAX_STYLE_C
42+
mostRecentFile.endsWith(".cpp") -> SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS
43+
mostRecentFile.endsWith(".go") -> SyntaxConstants.SYNTAX_STYLE_GO
44+
mostRecentFile.endsWith(".rs") -> SyntaxConstants.SYNTAX_STYLE_RUST
45+
else -> SyntaxConstants.SYNTAX_STYLE_RUST
46+
}
3747
}
3848
}
3949

4050
fun getDwarfSourcemap(wasmFilename: String): SourceMap {
4151
val process = ProcessBuilder(
42-
"./dwarf-line-mapping",
52+
if (SystemInfo.isMacOS) "./dwarf-line-mapping-mac" else "./dwarf-line-mapping",
4353
wasmFilename
4454
).redirectErrorStream(true).start()
4555

src/main/kotlin/be/ugent/topl/mio/ui/InteractiveDebugger.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ import kotlin.concurrent.thread
3636

3737
class InteractiveDebugger(
3838
connection: Connection,
39-
symbolicWdcliPath: String,
4039
private val sourceMapping: SourceMap? = null,
4140
private val wasmFile: String = "/home/maarten/Documents/School/Thesis/thesis-git/wardbg/simple-sym-test.wasm",
4241
private val config: DebuggerConfig
4342
) : JFrame("WARDuino Debugger") {
44-
private val binaryInfo = getBinaryInfo(symbolicWdcliPath, File(wasmFile).absolutePath)
43+
private val binaryInfo = getBinaryInfo(config.wdcliPath, File(wasmFile).absolutePath)
4544
private val debugger = MultiverseDebugger(
4645
connection,
4746
WasmBinary(File(wasmFile), binaryInfo),
48-
symbolicWdcliPath,
47+
config.symbolicWdcliPath,
4948
false,
5049
this::onGraphUpdate,
5150
this::onMockingUpdate,

src/main/kotlin/be/ugent/topl/mio/ui/StartScreen.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import be.ugent.topl.mio.DebuggerConfig
44
import be.ugent.topl.mio.connections.ProcessConnection
55
import be.ugent.topl.mio.connections.SerialConnection
66
import be.ugent.topl.mio.sourcemap.AsSourceMapping
7+
import be.ugent.topl.mio.sourcemap.getDwarfSourcemap
78
import com.fazecast.jSerialComm.SerialPort
89
import com.formdev.flatlaf.extras.FlatSVGIcon
910
import com.formdev.flatlaf.util.SystemFileChooser
1011
import java.awt.Dimension
1112
import java.io.File
1213
import java.io.FileInputStream
1314
import java.io.FileWriter
15+
import java.io.IOException
1416
import java.util.*
1517
import javax.swing.*
1618

@@ -87,11 +89,17 @@ open class StartScreen(config: DebuggerConfig) : AboutScreen(config) {
8789
}
8890
val sourceMapFile = File(binary.path + ".map")
8991
if (!sourceMapFile.exists()) {
90-
JOptionPane.showMessageDialog(this, "File does not have an associated sourcemap (.map) file!", "Missing sourcemaps", JOptionPane.ERROR_MESSAGE)
91-
return false
92+
try {
93+
val sourceMapping = getDwarfSourcemap(binary.path)
94+
InteractiveDebugger(connection, sourceMapping, binary.path, config = config)
95+
return true
96+
} catch(e: IOException) {
97+
JOptionPane.showMessageDialog(this, "Could not obtain DWARF debug info from \"${binary}\". Sourcemaps (.map) are also supported but no valid sourcemap was found for this binary.\n\nDetails:\n${e.message}\n", "Failed to get debug info", JOptionPane.ERROR_MESSAGE)
98+
return false
99+
}
92100
}
93101
val sourceMapping = AsSourceMapping(File(binary.path + ".map").readText())
94-
InteractiveDebugger(connection, config.symbolicWdcliPath, sourceMapping, binary.path, config = config)
102+
InteractiveDebugger(connection, sourceMapping, binary.path, config = config)
95103
return true
96104
}
97105
}

0 commit comments

Comments
 (0)