Skip to content

Modify ocamldebug to handle Dune workspace mapping #12083

@richardlford

Description

@richardlford

In order to produce reproducible builds (independent of the location of the build), starting from Dune 3.0, Dune has mapped references to the workspace directory to “/workspace_root”. The source/load path directories contained in debug information produced by ocamlc were affected by this change, for users who build their projects with Dune. The result is that ocamldebug sometimes is unable to find the program source code.

Starting in Dune 3.7, a dune-project stanza was added to suppress the workspace mapping.

(map_workspace_root <bool>)

This enables users to get programs that ocamldebug can handle, at the expense of not having reproducible builds.

Another workaround is for the ocamldebug user to add -I <dir> options showing where the sources are.

Note that if the project uses bin and lib directories, as suggested by dune init project, then the source file references in the debug information will be things like "bin/main.ml" or "lib/mod.ml". Currently, the emacs "ocamldebug" command that is used
to start ocamldebug, changes to the directory of the bytecode file, e.g. _build/default/bin. From that directory, it will not
be able to find the sources. If, before trying to do anything that causes the program to load, the user uses "cd" to move up to the directory containing "_build", then the relative paths in the debug events will work ok. That is yet another workaround for users.

This feature request proposes an ocamldebug change that is relatively simple and would work most of the time. Since it is Dune that is causing the problem, it will not occur unless the user is using Dune to build their project. In that case, the build artifacts are contained in a "_build" directory (at least by default). ocamldebug can look at the location of the binary being debugged (or of additional binaries loaded dynamically). If they are contained in a "_build" directory, then the occurrences of "/workspace_root" can be mapped to the directory containing the _build directory. That should restore the directories to what they were without the mapping.

I have a version of ocamldebug that has been so modified and plan to submit a PR soon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions