Jackson Tale
Jackson Tale

Reputation: 25812

How to properly debug OCaml code?

Can I know how an experienced OCaml developer debugs his code?

What I am doing is just using Printf.printf. It is too troublesome as I have to comment them all out when I need a clean output.

How should I better control this debugging process? special annotation to switch those logging on or off?

thanks

Upvotes: 6

Views: 677

Answers (3)

Çağdaş Bozman
Çağdaş Bozman

Reputation: 2540

You can also use ocp-ppx-debug which will add a printf with the good location instead of adding them manually.

https://github.com/OCamlPro-Couderc/ocp-ppx-debug

Upvotes: 2

rafix
rafix

Reputation: 1749

You can use bolt for this purpose. It's a syntax extension.

Btw. Ocaml has a real debugger.

Upvotes: 8

Guy Coder
Guy Coder

Reputation: 24976

There is a feature of the OCaml debugger that you may not be aware of which is not commonly found with stateful programming and is called time travel. See section 16.4.4. Basically since all of the information from step to step is kept on the stack, by keeping the changes associated with each step saved during processing, one can move through the changes in time to see the values during that step. Think of it as running the program once logging all of the values at each step into a data store then indexing into that data store based on a step number to see the values at that step.

Upvotes: 4

Related Questions