What is the modern way for analyzing/inspecting/fine-tuning an OCaml program?

Usually, if a functional program compiles and if it addresses correctly the requirements of the end-user, things are often going well. Of course, some troubles may always appear with uncatched exception (out of bounds, wrong control flow, etc.).

It’s not enough, but it’s a good thing to inspect what is going on during program execution: find the cause of an exception, and also execute it step by step, print some values, etc.

There are the good old #trace and #untrace. There is ocd (ocamldebugger) and its simple commands (r b bt) to get a backtrace manually.

I can also hard code a few print expressions in some branches to see if the program uses them and inspect the values at that moment.

There is Printexc stdlib, which I never used, and which has drawbacks.

This 2013 ExceptionHandling library: A library to record OCaml backtraces improves the use of Printexc. It gives you “good backtraces with a reasonable price performance price… which only exists when you turn on backtrace recording”.

I see that there a few opam packages related to “debug” or analyze/analysis.

Is the library ExceptionHandling always a reference?
What is the most modern way to run step by step an OCaml program from the editor (Emacs/vim) with breakpoints/probes?

In 2020, what are the available tools and modern way for doing what I’ve shortly described herebefore?

1 Like