Dune + ocamldebug

I’m trying to figure out how to use ocamldebug, although it seems quite easy on the wiki, I find it difficult to apply it to an actual dune project.

For example, I made a project with dune init proj hello and added (modes byte) to bin/dune, then I modified sources to bring dependency on
internal library:

(* lib/hello.ml *)

let greeting = "Hello"
(* bin/main.ml *)

open Hello

let () =
  let message = greeting ^ ", World!" in
  print_endline message

Next, I launch debugger and see that it cannot find library:

$ ocamldebug _build/default/bin/main.bc

(ocd) break @ Dune__exe__Main 5

(ocd) r
Time: 21 - pc: 0:11272 - module Dune__exe__Main
Breakpoint: 1
5   <|b|>print_endline message

(ocd) p message
Cannot find module Hello.

so I fixed this with include

$ ocamldebug -I _build/default/lib/.hello.objs/byte/ _build/default/bin/main.bc 


(ocd) p message
message: string = "Hello, World!"

But it doesn’t feel right to me, as I need to include manually every library that a project uses, and paths to them are not obvious.

Two questions:

  1. Is there a way to include all libraries of a project?
  2. Also ocamldebug manual states that everything should be compiled with -g flag, do I need to add it to all dune project files?
1 Like

dune will add -g flag for you by default