-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Byte target can't be debugged with ocamldebug #4347
Comments
Thanks for the detailed report. I had a look and found the issue; it is because of the name mangling Dune does to avoid collision between modules of different libraries and/or modules of the executable. More precisely, OCaml has a flat namespace, meaning that the name of each compilation unit (= toplevel module) must be unique. So if library A has a toplevel module named M and library B also has a toplevel module named M, then A and B cannot be used together in the same program. To workaround this limitation, Dune compiles modules of libraries and executables to compilation unit with a long name. For instance, module M of library A is compiled to We tried to hide these long names, but unfortunately they sometimes leak. Debugging is an example where you will see these long names. So here, you need to put the breakpoint on
We should probably document this in the manual. It is unfortunate that users have to do this, but unfortunately we can't solve it just on the Dune side. |
We discussed this issue during the Dune meeting today. It would be nice if On the Dune side, we'll consider this issue fixed when this is documented in the manual. |
Thanks @jeremiedimino for the explanation! I'm very new to OCaml so it was great to get a better understanding of flat namespacing and its consequences with how internal and external modules interact. If contributions to documentation are welcome, I'm happy to update the relevant section in the Quickstart with the information you've shared here? |
Such contributions are definitely welcome, please go ahead :) |
Expected Behavior
dune build
should produce a byte target for https://github.com/disposedtrolley/hello_ocaml which is able to be debugged withocamldebug
. A breakpoint should be able to be set on line 2 of thehelloworld
module.Actual Behavior
While
dune build
is able to build a.bc
file, it seems to be missing debug symbols. For example, attempting to set a breakpoint on line 2 ofhelloworld.ml
results in:When the project is built with
ocamlc -g helloworld.ml
, the resultinga.out
file can be debugged withocamldebug
correctly.Reproduction
dune build
ocamldebug _build/default/helloworld.bc
break @helloworld 2
Specifications
dune
(output ofdune --version
): 2.8.4ocaml
(output ofocamlc --version
) 4.12.0Additional information
I've tried this with OCaml 4.12 (on macOS with Apple Silicon) and 4.10.2 (on macOS with Apple Silicon and Fedora 33 x86).
The text was updated successfully, but these errors were encountered: