Skip to content
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

Support source maps between editor and debugger file paths #1030

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gpanders
Copy link
Contributor

@gpanders gpanders commented Sep 1, 2023

When nvim-dap is running on a separate machine from the debugger then Nvim and the debugger will use different paths for source files. For example, if Nvim is running on a machine where the source tree is located at /a/project/foo and the debugger is running on a separate machine where the source tree is located at /b/project/foo, when nvim-dap tries to set a breakpoint it will use /a/project/foo/ in the breakpoint location. When the debugger receives this request it will not set the breakpoint correctly because the debugger does not have any files at /a/project/foo.

The source_map option instructs nvim-dap to convert paths as seen by the editor and nvim-dap itself to the paths as the debugger sees them. The opposite mapping takes place when nvim-dap receives stack frame or source file information from the debugger.

Note that this is different than the "source map" option provided by many debuggers themselves (such as codelldb's "sourceMap" option or GDB's "substitute-path" setting). Those options convert compiled source paths (i.e. the path of the source file when the binary was compiled) into the debugger's path namespace (/b/project/foo in our example).

When nvim-dap is running on a separate machine from the debugger then
Nvim and the debugger will use different paths for source files. For
example, if Nvim is running on a machine where the source tree is
located at /a/project/foo and the debugger is running on a separate
machine where the source tree is located at /b/project/foo, when
nvim-dap tries to set a breakpoint it will use /a/project/foo/ in the
breakpoint location. When the debugger receives this request it will not
set the breakpoint correctly because the debugger does not have any
files at /a/project/foo.

The source_map option instructs nvim-dap to convert paths as seen by the
editor and nvim-dap itself to the paths as the debugger sees them. The
opposite mapping takes place when nvim-dap receives stack frame or
source file information from the debugger.

Note that this is different than the "source map" option provided by
many debuggers themselves (such as codelldb's "sourceMap" option or
GDB's "substitute-path" setting). Those options convert _compiled_
source paths (i.e. the path of the source file when the binary was
compiled) into the debugger's path namespace (/b/project/foo in our
example).
@brettmitchelldev
Copy link

brettmitchelldev commented Oct 12, 2023

This is fantastic. I routinely use volume mounts inside containers to develop, and it's hacky and inconvenient to mirror the host's directory structure inside the container.

I've tried this branch out and it solves the problem really well. 🚀

Perhaps the configuration could be assigned dynamically on a per-config and/or per-attach basis? Might make automation easier. Right now I'm automating assignment by mutating adapter.options.source_map directly by reference on attach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants