Ocamldebug using dune

Hello,

I created a project using dune. it is working fine. My dune config looks like

(executable
 (public_name merge_sort_mutable)
 (name main)
 (libraries merge_sort_mutable)
 (flags
  (:standard -g -o)))

I want to learn how to step through my code. so I did

  1. ocaldebug merge_sort_mutable
  2. This brings up a prompt with “(ocd)”

Now I try to setup a break point by

  1. break @ “bin/main.ml” 21
    but it says “Syntax error”

I also try

break @ merge_sort_mutable 21

but it says “Loading program… Program not found”

I can do list “bin/main.ml” and this prints my program but I cannot create a breakpoint and then step through my code.

I search this forum and found this thread Using ocamldebug with dune

I tried

break @ dune_exe_Main 21

but still Loading program … Program not found.

The correct syntax is

break @ Main 21

(module name, line number in source file)

Elaborating a bit more on the initial reply:

First, note that ocamldebug only works with the bytecode backend.
So remember to include the following line in your dune file

 (modes byte)

as in the other post you linked to. Then pass the name of the bytecode executable to ocamldebug, e.g., ocamldebug _build/default/merge_sort_mutable.bc.

As for breakpoints, dune renames the main module under the hood to avoid name clashes. This can be controlled with the option wrapped_executables in dune-project.
You may therefore have to set a breakpoint on the renamed module with:

break @Dune__exe__Main 21

Notice the Dune__exe__ prefix with double, not single underscores.

I haven’t checked how your usage of the same name merge_sort_mutable for both a public executable and a library plays together with the above renaming. For a start, I would probably play it safe myself and use, e.g., (public_name main) until I got it working…

Finally, I also recommend having a look at the ocamldebug chapter of the OCaml manual.

Note that ocamldebug has a command (don’t remember which right now)
with which you can list the modules.

Best regards