I know of the OCaml debugging tool (first compile with ocamlc -g <file>
, then run ocamldebug <output>
) and also the function call tracing feature in the toplevel (both covered here). However, I can't seem to find anything about debug builds with dune. Is this possible? Can someone point me in the right direction? Thank you!
The -g
flag is present by default in all build profiles, so the short answer is that you don't need to do anything. As a pro tip, if you want to see what flags are set by default use
dune printenv .
or for the given building profile, e.g., for release
,
dune printenv --profile release .
In a general case, flags are added using flags
, ocamlc_flags
, and ocamlopt_flags
fields that are accepted by env
, library
, executable
, and executables
stanzas and have the corresponding scopes. If you want your flag to be applied globally you need to add the corresponding flag field to env
stanza, e.g.,
(env
(release
(ocamlopt_flags (:standard -O3))))
Here :standard
expands to the standard set of flags.
It is also worth to know that OCaml native executables (the executables compiled to machine code using ocamlopt
) do not work with ocamldebug
. You can use either gdb
, which OCaml supports pretty well or use bytecode executables.