vm/cli: fix step command

It was setting a (wrong) breakpoint and couldn't then break out of it.
This commit is contained in:
Roman Khimov 2020-05-21 12:15:50 +03:00
parent 318ca55982
commit 328c6d7ce5

View file

@ -321,7 +321,13 @@ func runVMWithHandling(c *ishell.Context, v *vm.VM) {
c.Err(err)
return
}
checkAndPrintVMState(c, v)
}
// checkAndPrintVMState checks VM state and outputs it to the user if it's
// failed, halted or at breakpoint. No message is printed if VM is running
// normally.
func checkAndPrintVMState(c *ishell.Context, v *vm.VM) {
var message string
switch {
case v.HasFailed():
@ -364,8 +370,17 @@ func handleStep(c *ishell.Context) {
return
}
}
v.AddBreakPointRel(n)
runVMWithHandling(c, v)
for i := 0; i < n; i++ {
err := v.Step()
if err != nil {
c.Err(err)
return
}
checkAndPrintVMState(c, v)
}
ctx := v.Context()
i, op := ctx.CurrInstr()
c.Printf("at %d (%s)\n", i, op.String())
changePrompt(c, v)
}