ocamlearlybird icon indicating copy to clipboard operation
ocamlearlybird copied to clipboard

Support "StepBack" ?

Open gasche opened this issue 1 year ago • 3 comments

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?

gasche avatar Feb 24 '25 10:02 gasche

Yes, it's possible. But it needs lots work to do.

hackwaly avatar Feb 24 '25 10:02 hackwaly

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:

  • ocamldebug supports 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.
  • ocamlearlybird already 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.

gasche avatar Feb 24 '25 21:02 gasche

The architecture is already designed to allow adding time-travel feature easily:

  • Controller.t is the corresponding of checkpoint in ocamldebug.
  • By changing c: Controller.t field in Debugger.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.

hackwaly avatar Feb 25 '25 09:02 hackwaly