Skip to content

Commit 1acea7c

Browse files
committed
Add a graphical error message when a program cannot be loaded by the debugger
1 parent 2cd245c commit 1acea7c

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ data class WasmInfo(
1212
)
1313
data class WasmBinary(val file: File, val metadata: WasmInfo)
1414

15-
fun getBinaryInfo(wdcliPath: String, wasmFile: String): WasmInfo {
15+
fun getBinaryInfo(wdcliPath: String, wasmFile: String): Result<WasmInfo> {
1616
println("Get binary info using $wdcliPath")
1717
val process = ProcessBuilder(wdcliPath, wasmFile, "--no-socket", "--dump-info").redirectErrorStream(true).start()
1818
val lineScanner = Scanner(process.inputStream)
@@ -24,13 +24,13 @@ fun getBinaryInfo(wdcliPath: String, wasmFile: String): WasmInfo {
2424
val objectMapper = ObjectMapper()
2525
objectMapper.registerKotlinModule()
2626
process.destroy()
27-
return objectMapper.readValue(currentLine, WasmInfo::class.java)
27+
return Result.success(objectMapper.readValue(currentLine, WasmInfo::class.java))
2828
}
2929
}
3030
process.destroy()
3131
println("Output:")
3232
for (line in lines) {
3333
println(line)
3434
}
35-
throw Exception("Failed to get info")
35+
return Result.failure(Exception(lines.joinToString("\n")))
3636
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import javax.swing.event.DocumentEvent
3232
import javax.swing.event.DocumentListener
3333
import javax.swing.table.DefaultTableModel
3434
import kotlin.concurrent.thread
35+
import kotlin.system.exitProcess
3536

3637

3738
class InteractiveDebugger(
@@ -40,7 +41,10 @@ class InteractiveDebugger(
4041
private val wasmFile: String = "/home/maarten/Documents/School/Thesis/thesis-git/wardbg/simple-sym-test.wasm",
4142
private val config: DebuggerConfig
4243
) : JFrame("WARDuino Debugger") {
43-
private val binaryInfo = getBinaryInfo(config.wdcliPath, File(wasmFile).absolutePath)
44+
private val binaryInfo = getBinaryInfo(config.wdcliPath, File(wasmFile).absolutePath).getOrElse {
45+
JOptionPane.showMessageDialog(this, it.message, "Error obtaining binary info", JOptionPane.ERROR_MESSAGE)
46+
exitProcess(1)
47+
}
4448
private val debugger = MultiverseDebugger(
4549
connection,
4650
WasmBinary(File(wasmFile), binaryInfo),

0 commit comments

Comments
 (0)