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
-
1Does this answer your question? Debugging with duneChris– Chris2024年06月15日 01:57:11 +00:00Commented 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.Costava– Costava2025年03月28日 03:03:28 +00:00Commented Mar 28, 2025 at 3:03
1 Answer 1
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