Support "StepBack" ?
Unless I am missing something, using earlybird from vscode does not let users step back from the debugger -- StepIn and StepOut both move forward in times. The OCaml debugger supports going back in time, and this is a rather convenient workflow to debug a crash: "run" the debugger until the crash location, and then "step back" repeatedly to reconstruct what was going on before the crash.
It looks like the DAP specification does support a StepBack request, and also a "ReverseContinue" request (which I suppose runs back until the beginning of the program or a breakpoint is reached). Would it be possible to support this in earlybird?
Yes, it's possible. But it needs lots work to do.
In case someone is interested in implementing this, could you say just a bit more about how this would have to be done? Here is what I think I understand:
-
ocamldebugsupports time-travel by maintaining a list of "checkpoints", which correspond to copies of the program state at specific points in the execution. When we ask to go back in time, it reloads the previous checkpoint. - We would need to implement similar logic in
ocamlearlybird(maintaining a table of checkpoints and navigating them). - The really heavy lifting in how to implement checkpoints (calling
fork()to create a copy of the program state and suspending the result) is done by the OCaml runtime itself, so we wouldn't need to reimplement that. -
ocamlearlybirdalready supports asking the OCaml runtime to create a new checkpoint through the wire protocol.
The code for tracking and navigating checkpoints in ocamldebug is at https://github.com/ocaml/ocaml/blob/3ca06d6e669aed7ca457d20f10fca133a38dc381/debugger/time_travel.ml . It's a fair amount of code, more than I expected.
The architecture is already designed to allow adding time-travel feature easily:
-
Controller.tis the corresponding ofcheckpointin ocamldebug. - By changing
c: Controller.tfield inDebugger.t, can do time-travel.
The tough thing is to debug ocamlearlybird itself once implemented time-travel to make it works properly and add tests for that.