-1

Let's say I:

dune init proj foobar
cd foobar

Then modify test/test_foobar.ml to be:

let () = print_endline "First"
let () = print_endline "Second"
let () = print_endline "Third"

I can execute the program with dune test.
How can I run the program and step each line individually in a debugger with source available? Either ocamldebug or gdb is probably fine.

I can do gdb --tui --args ./_build/default/test/test_foobar.exe but it does NOT show the source.

I don't see any suitable files to launch with ocamldebug e.g.:

$ ocamldebug ./_build/default/test/test_foobar.ml
 OCaml Debugger version 5.2.0
(ocd) r
Loading program... < shortened >/foobar/./_build/default/test/test_foobar.ml is not a bytecode file.

Working with OCaml 5.2.0 and dune 3.15.3

asked Jun 15, 2024 at 1:31
2
  • 1
    Does this answer your question? Debugging with dune Commented Jun 15, 2024 at 1:57
  • @Chris That is some good info but the sticking point for me was that gdb does not show the OCaml source until a breakpoint is hit. gdb will confusingly run all the way to the end of the program and show "No Source Available" the whole time. I am used to gdb's behavior with C programs where the source is shown immediately before the program even starts. Commented Mar 28, 2025 at 3:03

1 Answer 1

0

Add (modes byte exe) to your test/dune file to cause a byte-code version to be built also e.g. _build/default/test/test_foobar.bc which can be run in ocamldebug.

The test/dune file:

(test
 (name test_foobar)
 (modes byte exe)
)

---

gdb does run to the end of the program while showing "No Source Available" the whole time.
If you set a breakpoint and hit it though, the source will appear.

e.g.

(gdb) break test/test_foobar.ml:1
answered Jul 8, 2024 at 2:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.