Skip to content

Commit fae797e

Browse files
committed
Use ?. instead of !! to cleanly handle null states in stepBack
1 parent 119f6f1 commit fae797e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/main/kotlin/be/ugent/topl/mio/debugger/Debugger.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ open class Debugger(private val connection: Connection, start: Boolean = true, p
260260
}
261261
println("count = ${checkpoints.size}")
262262
}
263+
263264
open fun stepBack(n: Int, binaryInfo: WasmInfo, stepDone: () -> Unit = {}) {
264265
if (n == 0) {
265266
return
@@ -272,7 +273,7 @@ open class Debugger(private val connection: Connection, start: Boolean = true, p
272273
//if (snapshot != null) {
273274
println("Snapshot to ${checkpoint.snapshot.pc}")
274275
val s = checkpoint.snapshot
275-
s.breakpoints = currentState!!.snapshot.breakpoints
276+
s.breakpoints = currentState?.snapshot?.breakpoints // The current state can be null if the data about this checkpoint was removed.
276277
loadSnapshot(s)
277278
}
278279
stepDone()
@@ -289,7 +290,7 @@ open class Debugger(private val connection: Connection, start: Boolean = true, p
289290
if (checkpoint != null) {
290291
println("Jumping to ${checkpoint.snapshot.pc}")
291292
val s = checkpoint.snapshot
292-
s.breakpoints = currentState!!.snapshot.breakpoints
293+
s.breakpoints = currentState?.snapshot?.breakpoints
293294
loadSnapshot(s)
294295
break
295296
}
@@ -330,7 +331,7 @@ open class Debugger(private val connection: Connection, start: Boolean = true, p
330331
s.breakpoints = s.breakpoints!!.toMutableList() - address
331332
}
332333
fun disableAllBreakpoints(): List<Int> {
333-
val breakpointsStart = checkpoints.last()!!.snapshot.breakpoints!!
334+
val breakpointsStart = checkpoints.last()!!.snapshot.breakpoints?: emptyList()
334335
for (breakpoint in breakpointsStart) {
335336
removeBreakpoint(breakpoint)
336337
}

0 commit comments

Comments
 (0)