# Ocamldebug using dune

**URL:** <https://discuss.ocaml.org/t/ocamldebug-using-dune/15595>\
**Category:** Learning\
**Created:** [November 12, 2024, 1:05am UTC](https://discuss.ocaml.org/t/ocamldebug-using-dune/15595 "2024-11-12T01:05:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishes](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@abhishes](https://discuss.ocaml.org/u/abhishes)\
**Post date:** [November 12, 2024, 1:05am UTC](https://discuss.ocaml.org/t/ocamldebug-using-dune/15595/1 "2024-11-12T01:05:27Z")

</div>

Hello,

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

```auto
(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](https://discuss.ocaml.org/t/using-ocamldebug-with-dune/7878)

I tried

break @ dune\_exe\_Main 21

but still Loading program … Program not found.

---

<div class="post-metadata">

**Author:** ![jserot](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jserot/32/2294_2.png) [@jserot](https://discuss.ocaml.org/u/jserot)\
**Post date:** [November 12, 2024, 8:45am UTC](https://discuss.ocaml.org/t/ocamldebug-using-dune/15595/2 "2024-11-12T08:45:02Z")

</div>

> [@abhishes](#):
>
> Now I try to setup a break point by
> 
> 1. break @ “bin/main.ml” 21  
> but it says “Syntax error”

The correct syntax is

```auto
break @ Main 21

```

(module name, line number in source file)

---

<div class="post-metadata">

**Author:** ![jmid](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jmid](https://discuss.ocaml.org/u/jmid)\
**Post date:** [November 12, 2024, 11:36am UTC](https://discuss.ocaml.org/t/ocamldebug-using-dune/15595/3 "2024-11-12T11:36:26Z")

</div>

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

```auto
 (modes byte)

```

as [in the other post you linked to](https://discuss.ocaml.org/t/using-ocamldebug-with-dune/7878). 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](https://dune.readthedocs.io/en/stable/reference/dune-project/wrapped_executables.html).  
You may therefore have to set a breakpoint on the renamed module with:

```auto
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](https://ocaml.org/manual/5.2/debugger.html).

---

<div class="post-metadata">

**Author:** ![ttamttam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ttamttam/32/132_2.png) [@ttamttam](https://discuss.ocaml.org/u/ttamttam)\
**Post date:** [November 12, 2024, 12:57pm UTC](https://discuss.ocaml.org/t/ocamldebug-using-dune/15595/4 "2024-11-12T12:57:43Z")

</div>

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

Best regards
