Breakpoint does not work if working directory path contains symbolic link #74

Closed
opened 2024-03-20 11:17:40 +03:00 by shu-bc · 5 comments
shu-bc commented 2024-03-20 11:17:40 +03:00 (Migrated from github.com)

I found that if current working directory path contains symbolic link, running require('dap-go').debug_test() will ignore breakpoint.


It is like following:

  • create directory ~/workspace/gotest
  • create directory & files like this
スクリーンショット 2024-03-20 17 16 11
  • create symbolic link in home directory, by run ln -s gotest ~/workspace/gotest
  • change directory through symblic link, cd gotest

Then set arbitrary breakpoint, and run require('dap-go').debug_test().

This will not happen by running require('dap').cotinue() and select 1 to debug main.go, even working directory path contains symbolic link. So I suppose it is caused by debug_test function.

I found that if current working directory path contains symbolic link, running `require('dap-go').debug_test()` will ignore breakpoint. --- It is like following: - create directory `~/workspace/gotest` - create directory & files like this <img width="1591" alt="スクリーンショット 2024-03-20 17 16 11" src="https://github.com/leoluz/nvim-dap-go/assets/52311472/dce8a144-4d38-4a32-a0d5-c52d31ecd081"> - create symbolic link in home directory, by run `ln -s gotest ~/workspace/gotest` - change directory through symblic link, `cd gotest` Then set arbitrary breakpoint, and run `require('dap-go').debug_test()`. This will not happen by running `require('dap').cotinue()` and select 1 to debug `main.go`, even working directory path contains symbolic link. So I suppose it is caused by `debug_test` function.
leoluz commented 2024-03-25 05:15:30 +03:00 (Migrated from github.com)

It seems that this is the problem:
leoluz/nvim-dap-go@36abe1d320/lua/dap-go-ts.lua (L137C27-L137C59)
I didn't initially found a filename modifier to work with symlinks:
https://neovim.io/doc/user/cmdline.html#filename-modifiers

Maybe consider using real files instead of symlinks?

It seems that this is the problem: https://github.com/leoluz/nvim-dap-go/blob/36abe1d320cb61bfdf094d4e0fe815ef58f2302a/lua/dap-go-ts.lua#L137C27-L137C59 I didn't initially found a filename modifier to work with symlinks: https://neovim.io/doc/user/cmdline.html#filename-modifiers Maybe consider using real files instead of symlinks?
marcsc13 commented 2024-09-08 16:46:22 +03:00 (Migrated from github.com)

jTo be upfront, there is probably a better way of solving this. I have a workaround which is described below.

I open my projects in /home/marc/dev which is a symlink to /mnt/Data/dev on an additional SSD mounted to /mnt/Data during startup. You might need to change the paths.

I solved it with overwriting the config which is passed to dap when calling nvim-dap-go.debug_test():

{
    "leoluz/nvim-dap-go",
    event = "VeryLazy",
    ft = "go",
    dependencies = { "nvim-dap", "rcarriga/nvim-dap-ui" },
    config = function(_, opts)
      local dap, dapui = require "dap", require "dapui"
      local dapgo = require "dap-go"
      dapgo.setup(opts)
      dapui.setup()
      map("n", "<leader>dgt", function()
        local function debug_test(testname, testpath, build_flags, extra_args)
          local config = {
            type = "go",
            name = testname,
            request = "launch",
            mode = "test",
            program = testpath,
            args = { "-test.run", "^" .. testname .. "$" },
            buildFlags = build_flags,
            substitutePath = {
              { from = "/mnt/Data/dev", to = "/home/marc/dev" },
            },
          }

          if not vim.tbl_isempty(extra_args) then
            table.move(extra_args, 1, #extra_args, #config.args + 1, config.args)
          end

          dap.run(config)
        end
        local dapgots = require "dap-go-ts"
        local test = dapgots.closest_test()

        if test.name == "" or test.name == nil then
          vim.notify "no test found"
          return false
        end

        dapgo.last_testname = test.name
        dapgo.last_testpath = test.package

        local msg = string.format("starting debug session '%s : %s'...", test.package, test.name)
        vim.notify(msg)

        local extra_args = {}
        debug_test(test.name, test.package, dapgo.test_buildflags, extra_args)
        dapui.open()
      end, { desc = "Debug go test" })
    end,
  },

No other methods were overwritten. test.package returns the correct path for me.

delve or dap (don't know to be honest) provide a way of substituting paths when symlinks are used. https://go.googlesource.com/vscode-go/+/c3516da303907ca11ee51e64f961cf2a4ac5339a/docs/dlv-dap.md

jTo be upfront, there is probably a better way of solving this. I have a workaround which is described below. I open my projects in `/home/marc/dev` which is a symlink to `/mnt/Data/dev` on an additional SSD mounted to `/mnt/Data` during startup. You might need to change the paths. I solved it with overwriting the config which is passed to dap when calling `nvim-dap-go.debug_test()`: ```lua { "leoluz/nvim-dap-go", event = "VeryLazy", ft = "go", dependencies = { "nvim-dap", "rcarriga/nvim-dap-ui" }, config = function(_, opts) local dap, dapui = require "dap", require "dapui" local dapgo = require "dap-go" dapgo.setup(opts) dapui.setup() map("n", "<leader>dgt", function() local function debug_test(testname, testpath, build_flags, extra_args) local config = { type = "go", name = testname, request = "launch", mode = "test", program = testpath, args = { "-test.run", "^" .. testname .. "$" }, buildFlags = build_flags, substitutePath = { { from = "/mnt/Data/dev", to = "/home/marc/dev" }, }, } if not vim.tbl_isempty(extra_args) then table.move(extra_args, 1, #extra_args, #config.args + 1, config.args) end dap.run(config) end local dapgots = require "dap-go-ts" local test = dapgots.closest_test() if test.name == "" or test.name == nil then vim.notify "no test found" return false end dapgo.last_testname = test.name dapgo.last_testpath = test.package local msg = string.format("starting debug session '%s : %s'...", test.package, test.name) vim.notify(msg) local extra_args = {} debug_test(test.name, test.package, dapgo.test_buildflags, extra_args) dapui.open() end, { desc = "Debug go test" }) end, }, ``` > No other methods were overwritten. test.package returns the correct path for me. delve or dap (don't know to be honest) provide a way of substituting paths when symlinks are used. https://go.googlesource.com/vscode-go/+/c3516da303907ca11ee51e64f961cf2a4ac5339a/docs/dlv-dap.md
bvdeenen commented 2024-11-16 20:13:26 +03:00 (Migrated from github.com)

I have more or less the same issue when using c++. I have a similar situation where ~/Documents/dev points somewhere else (either via a symlink or a mounted bind!). The breakpoint I've set will not be picked up. However, if I launch from the original directory, everything is fine, so I'll just use that as a workaround.

I have more or less the same issue when using c++. I have a similar situation where `~/Documents/dev` points somewhere else (either via a symlink or a mounted bind!). The breakpoint I've set will not be picked up. However, if I launch from the original directory, everything is fine, so I'll just use that as a workaround.
dennypenta commented 2025-02-13 14:41:39 +03:00 (Migrated from github.com)

there is a similar problem with discovering breakpoints in the modules.
If I jump inside the source of the modules I use Im able to set breakpoint and even the breakpoint itself works fine.
but when the code jumps to the breakpoint it opens another empty buffer and shows an error:

Adapter reported a frame in buf 31 line 246 column 1, but: Cursor position outside buffer. Ensure executable is up2date and if using a source mapping ensure it is correct

It seems it can't resolve modules existing buffers.
it can be done by a fullpath or taking a module hash commit (a bit more complicated, but reliable to differentiate the versions in go/mod).

sometime later even those breakpoints stopped working leaving the breakpoint icon red (no clue what it means)

there is a similar problem with discovering breakpoints in the modules. If I jump inside the source of the modules I use Im able to set breakpoint and even the breakpoint itself works fine. but when the code jumps to the breakpoint it opens another empty buffer and shows an error: ``` Adapter reported a frame in buf 31 line 246 column 1, but: Cursor position outside buffer. Ensure executable is up2date and if using a source mapping ensure it is correct ``` It seems it can't resolve modules existing buffers. it can be done by a fullpath or taking a module hash commit (a bit more complicated, but reliable to differentiate the versions in go/mod). sometime later even those breakpoints stopped working leaving the breakpoint icon red (no clue what it means)
stale[bot] commented 2025-08-12 15:59:35 +03:00 (Migrated from github.com)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
NeonXP/nvim-dap-go#74
No description provided.