hannobraun / caterpillar

An experimental project to create an interactive programming language.
https://capi.hannobraun.com/
Other
16 stars 1 forks source link

"Stop" button in debugger can stop process at invisible instruction, breaking "Step" and "Continue" #53

Open hannobraun opened 1 month ago

hannobraun commented 1 month ago

Description

When pressing "Stop" in the debugger, the process can stop at an invisible instruction that has no fragment associated with it. In fact, this happens reliably when stopping the Snake game.

Screenshot from 2024-09-14 13-04-52

In this screenshot, the process has just executed the call to the submit_frame host function, which was then handled by the game engine. (The way the game engine is currently, it doesn't handle commands until a frame has been submitted, which is why the game always reliably stops here.) Since the effect has been handled, the process has advanced to the next instruction, which happens to be the invisible "return" instruction, which has no fragment associated with it that the debugger could show.

This is especially problematic, since the step button is displayed next to the active fragment, which means no step button is displayed here.

Workaround

You can set a breakpoint anywhere in the code displayed here, and then press "Continue". This will run the game for another frame and stop at the breakpoint. From there, you have a "Step Into" button again. (Beware of https://github.com/hannobraun/caterpillar/issues/52 though.)

Proposed Solution

The debugger can detect this condition, and simply tell the process to evaluate one more instruction. (And if that leads to the same result, just repeat until we reach a fragment or the process finishes.)

As of this writing, no command exists that could tell the process to do that, but it should be trivial to add one. (And I'm pretty sure I'll add one soon anyway, as I think it's required for fixing https://github.com/hannobraun/caterpillar/issues/52.)

hannobraun commented 1 month ago

This just got a bit more broken, as a result of fixing https://github.com/hannobraun/caterpillar/issues/54. When trying to continue, as suggested in the workaround, the debugger crashes. A new workaround might be to set a breakpoint, then click "Reset" instead of "Continue".

To be clear, the fixed "Continue" operation has the correct behavior. The problem is with "Stop" stopping at an invisible instruction.

hannobraun commented 1 month ago

This problem is no longer reproducible, as it is being masked by https://github.com/hannobraun/caterpillar/issues/55. The bug is still present in the code though, and should become reproducible again, once https://github.com/hannobraun/caterpillar/issues/55 is fixed.

hannobraun commented 1 month ago

55 is fixed. This bug has become reproducible again.