How can I obtain the complete traces of an execution?

I am a beginner of OCaml and Dune. Thanks to the great OCaml discuss community, I successfully learned how to debug ocaml in terminal (via ocamldebug) and in VSCode (via ocamlearlybird plugin). But I find both debugging approaches do not provide a complete execution trace (e.g., a list of every executed location) for a single execution.

Is there any way to obtain such information? I think this would be super helpful when debugging a large-scale OCaml project.

1 Like

You can prefix your build command with OCAMLRUNPARAM=b as previously answered. I alias OCAMLRUNPARAM=b dune to dunetrace for slightly more convenient use when I want to turn traces on for debugging.

1 Like

Thank you very much for the prompt and useful reply! That really helps.

I just tried this command OCAMLRUNPARAM=b and seemingly it only prints a complete backtrace when an exception is raised. How can we obtain the full trace when the execution normally exits? Many thanks!

You could try ppx_debug (disclaimer: my project). It’s pretty much about instrumenting code to log every executed location, using cmt files to figure out the printers to use. The original motivation for it was exactly what you mentioned, debugging a huge OCaml project.

It’s got some rough edges as the current version hasn’t really been tried in the wild, but feel free to open issues if you find problems.


Thank you very much for contributing this tool to the community! I will take a try soon.