Skip to content

Commit 96a9b95

Browse files
committed
Slide now resets the execution instead of stepping back
It also warns the user if it does that.
1 parent 6018eb6 commit 96a9b95

5 files changed

Lines changed: 51 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,13 @@ open class Debugger(private val connection: Connection, start: Boolean = true, p
392392
fun dumpVMState() = send(10)
393393
fun dumpLocals() = send(11)
394394
fun dumpStateAndLocals() = send(12)
395-
fun reset() = send(13)
395+
open fun reset() {
396+
val firstState = checkpoints.first()
397+
checkpoints.clear()
398+
checkpoints.add(firstState)
399+
send(13)
400+
checkpointsUpdated()
401+
}
396402

397403
fun snapshot(): String {
398404
send(60)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ open class MultiverseNode(val children: MutableList<MultiverseNode> = mutableLis
7575

7676
fun findPath(n: MultiverseNode): MutableList<MultiverseNode> {
7777
val path = mutableListOf(this)
78-
findPath(n, path)
78+
if (!findPath(n, path)) return mutableListOf()
7979
return path
8080
}
8181

@@ -230,6 +230,12 @@ class MultiverseDebugger(
230230
super.run()
231231
}
232232

233+
override fun reset() {
234+
super.reset()
235+
graph.currentNode = graph.rootNode
236+
graphUpdated()
237+
}
238+
233239
override fun addPrimitiveOverride(primName: String, arg: Int, returnValue: Int) {
234240
super.addPrimitiveOverride(primName, arg, returnValue)
235241
if (!overrides.containsKey(primName))

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
186186

187187
var selectedNodes = mutableSetOf<MultiverseNode>()
188188
var selectedPath: Pair<List<MultiverseNode>, List<MultiverseNode>>? = null
189+
var reset = true
189190
var completedPath = mutableSetOf<MultiverseNode>()
190191
override fun mouseClicked(e: MouseEvent) {
191192
if (!allowSelection) {
@@ -199,8 +200,15 @@ class GraphPanel(private val graph: MultiverseGraph) : JPanel(),
199200
}
200201
if (selectedNode == null) return
201202

202-
println(graph.rootNode.findPath(graph.currentNode, selectedValue!!))
203-
selectedPath = graph.rootNode.findPath(graph.currentNode, selectedValue!!)
203+
//selectedPath = graph.rootNode.findPath(graph.currentNode, selectedValue!!)
204+
if (graph.currentNode.findPath(selectedValue!!).isEmpty()) {
205+
selectedPath = Pair(listOf(), graph.rootNode.findPath(selectedValue!!))
206+
reset = true
207+
}
208+
else {
209+
selectedPath = Pair(listOf(), graph.currentNode.findPath(selectedValue!!))
210+
reset = false
211+
}
204212
selectedNodes = selectedPath!!.first.toMutableSet()
205213
selectedNodes.addAll(selectedPath!!.second.toSet())
206214

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import java.awt.event.WindowEvent
2828
import java.io.File
2929
import java.io.IOException
3030
import javax.swing.*
31+
import javax.swing.JOptionPane.ERROR_MESSAGE
32+
import javax.swing.JOptionPane.YES_NO_OPTION
3133
import javax.swing.event.DocumentEvent
3234
import javax.swing.event.DocumentListener
3335
import javax.swing.table.DefaultTableModel
@@ -68,14 +70,20 @@ class InteractiveDebugger(
6870
private val stepBackLineButton = JButton().apply {
6971
toolTipText = "Step to the previous line"
7072
}
73+
private val restartButton = JButton(FlatSVGIcon(javaClass.getResource("/debug-restart.svg"))).apply {
74+
addActionListener {
75+
debugger.reset()
76+
updatePcLabel()
77+
}
78+
}
7179
private val flashButton = JButton().apply {
7280
toolTipText = "Upload module to microcontroller"
7381
}
7482
private val progressBar = JProgressBar().apply {
7583
isVisible = false
7684
}
77-
private val allButtons = listOf(pauseButton, stepBackButton, stepOverButton, stepIntoButton, stepLineButton, stepBackLineButton, flashButton)
78-
private val pausedOnlyButtons = listOf(stepBackButton, stepOverButton, stepIntoButton, stepLineButton, stepBackLineButton)
85+
private val allButtons = listOf(pauseButton, stepBackButton, stepOverButton, stepIntoButton, stepLineButton, stepBackLineButton, restartButton, flashButton)
86+
private val pausedOnlyButtons = listOf(stepBackButton, stepOverButton, stepIntoButton, stepLineButton, stepBackLineButton, restartButton)
7987
private var paused = false
8088

8189
init {
@@ -240,6 +248,8 @@ class InteractiveDebugger(
240248
//toolBar.add(stepBackLineButton)
241249
toolBar.add(stepLineButton)
242250
toolBar.addSeparator()
251+
toolBar.add(restartButton)
252+
toolBar.addSeparator()
243253
toolBar.add(flashButton)
244254
//toolBar.addSeparator()
245255
if (config.checkpointHistory) {
@@ -471,7 +481,7 @@ class ContinueForAction(val debugger: Debugger, var n: Int) : MultiverseAction {
471481
class MultiversePanel(private val multiverseDebugger: MultiverseDebugger, config: DebuggerConfig, stateChanged: (c: Checkpoint?, b: Double) -> Unit) : JPanel() {
472482
private val graphPanel = GraphPanel(multiverseDebugger.graph)
473483
private val mockPanel = OverridesPanel()
474-
private val concolicButton = JButton("Suggest interesting paths")
484+
private val concolicButton = JButton("Suggest paths")
475485
private var maxInstructions = 50
476486
private val concolicOptionsButton = JButton().apply {
477487
val gearIcon = FlatSVGIcon(MultiverseDebugger::javaClass.javaClass.getResource("/settings-gear.svg"))
@@ -528,6 +538,7 @@ class MultiversePanel(private val multiverseDebugger: MultiverseDebugger, config
528538
stateChanged(null, 0.0)
529539
followButton.isEnabled = false
530540
customButton.isEnabled = false
541+
concolicButton.isEnabled = false
531542
thread {
532543
// Disable breakpoints
533544
val breakpointsStart = multiverseDebugger.checkpoints.last()!!.snapshot.breakpoints!!
@@ -565,6 +576,17 @@ class MultiversePanel(private val multiverseDebugger: MultiverseDebugger, config
565576
val lastAction = actionPath.last() as ContinueForAction
566577
lastAction.n++
567578
}
579+
if (graphPanel.reset) {
580+
if (JOptionPane.showConfirmDialog(this, "This operation will restart the execution, continue?", "Restart program", YES_NO_OPTION, ERROR_MESSAGE) == JOptionPane.NO_OPTION) {
581+
customButton.isEnabled = true
582+
followButton.isEnabled = true
583+
graphPanel.allowSelection = true
584+
concolicButton.isEnabled = true
585+
stateChanged(null, 1.0)
586+
return@thread
587+
}
588+
multiverseDebugger.reset()
589+
}
568590
for (action in actionPath) {
569591
action.doAction()
570592
if (action is ContinueForAction) {
@@ -597,6 +619,7 @@ class MultiversePanel(private val multiverseDebugger: MultiverseDebugger, config
597619
graphPanel.clearSelection()
598620
customButton.isEnabled = true
599621
graphPanel.allowSelection = true
622+
concolicButton.isEnabled = true
600623
}
601624
}
602625

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)