Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 749
Jackson Tale Avatar asked May 09 '13 08:05

Jackson Tale


3 Answers

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

Btw. Ocaml has a real debugger.

like image 142
rafix Avatar answered Nov 14 '22 18:11

rafix


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.

like image 4
Guy Coder Avatar answered Nov 14 '22 19:11

Guy Coder


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
like image 2
Çağdaş Bozman Avatar answered Nov 14 '22 18:11

Çağdaş Bozman