mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.4k stars 191 forks source link

Netcoredbg not stopping on breakpoints #1337

Open Rekwass opened 2 days ago

Rekwass commented 2 days ago

Debug adapter definition and debug configuration

Here is a minimal.lua file to reproduce the isssue:

vim.env.LAZY_STDPATH = '.repro'
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()

require('lazy.minit').repro {
    spec = {
        {
            'mfussenegger/nvim-dap',
            config = function()
                local dap = require("dap")

                dap.adapters.coreclr = {
                    type = "executable",
                    -- Make sure to change the path to find netcoredbg
                    command = "path/to/netcoredbg",
                    args = { '--interpreter=vscode' },
                }

                dap.configurations.cs = {
                    {
                        type = "coreclr",
                        name = "launch - netcoredbg",
                        request = "launch",
                        program = function()
                            return vim.fn.input('Path to dll', vim.fn.getcwd() .. '/bin/Debug/', 'file')
                        end,
                    },
                }
            end,
            lazy = false,
        },
    },
}

Make sure to run nvim --clean -u minimal.lua

Debug adapter version

3.1.1-1042

Steps to Reproduce

  1. Initialise a new project with dotnet new console -o testDap -f net8.0
  2. cd into the new project folder
  3. Open the Program.cs file and add a couple lines such as
    Console.WriteLine("Hello, World!");
    Console.WriteLine("Stop right there");
    Console.WriteLine("I said stop");
  4. Now make sure to build the solution in Debug mode (default). dotnet build -c Debug
  5. Set a breakpoint on lines 2 and 3 with :DapToggleBreakPoint
  6. Optional Set the log level to TRACE with :lua require('dap').set_log_level('TRACE')
  7. Start a dap session with DapContinue
  8. You will be prompted the path to the .dll file, it should be /path/to/file/testDap/bin/Debug/net8.0/testDap.dll
  9. After that all the breakpoints become DapBreakpointRejected and the session is closed without stopping on any breakpoints.

Expected Result

I expect the program to run and stop on the breakpoints that have been set. The debug adapter command works as it is able to find the executable and run it. It is also able to see my breakpoints. I saw on other issues that this is normal "The breakpoint is pending and will be resolved when debugging starts." as they should be evaluated when debugging starts (it is written clearly). I attempted to run the solution manually using dotnet bin/Debug/net8.0/testDap.dll without success. I also attempted to add the env and cwd fields but it does not resolve my issue. this solution.

Actual Result

The session is closed without stopping on any of the set breakpoints. The log file with TRACE log level.

[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1430 ]    "Spawning debug adapter"    {
  args = { "--interpreter=vscode" },
  command = "/path/to/netcoredbg/netcoredbg",
  type = "executable"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1742 ]    "request"   {
  arguments = {
    adapterID = "nvim-dap",
    clientID = "neovim",
    clientName = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "en_US.UTF-8",
    pathFormat = "path",
    supportsProgressReporting = true,
    supportsRunInTerminalRequest = true,
    supportsStartDebuggingRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 1,
  type = "request"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1009 ]    1   {
  body = {
    capabilities = {
      exceptionBreakpointFilters = { {
          filter = "user-unhandled",
          label = "user-unhandled"
        }, {
          filter = "all",
          label = "all"
        } },
      supportTerminateDebuggee = true,
      supportsCancelRequest = true,
      supportsConditionalBreakpoints = true,
      supportsConfigurationDoneRequest = true,
      supportsExceptionFilterOptions = true,
      supportsExceptionInfoRequest = true,
      supportsExceptionOptions = false,
      supportsFunctionBreakpoints = true,
      supportsSetExpression = true,
      supportsSetVariable = true,
      supportsTerminateRequest = true
    }
  },
  event = "capabilities",
  seq = "1",
  type = "event"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1009 ]    1   {
  body = vim.empty_dict(),
  event = "initialized",
  seq = "2",
  type = "event"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1009 ]    1   {
  body = {
    exceptionBreakpointFilters = { {
        filter = "user-unhandled",
        label = "user-unhandled"
      }, {
        filter = "all",
        label = "all"
      } },
    supportTerminateDebuggee = true,
    supportsCancelRequest = true,
    supportsConditionalBreakpoints = true,
    supportsConfigurationDoneRequest = true,
    supportsExceptionFilterOptions = true,
    supportsExceptionInfoRequest = true,
    supportsExceptionOptions = false,
    supportsFunctionBreakpoints = true,
    supportsSetExpression = true,
    supportsSetVariable = true,
    supportsTerminateRequest = true
  },
  command = "initialize",
  request_seq = 1,
  seq = "3",
  success = true,
  type = "response"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1742 ]    "request"   {
  arguments = {
    breakpoints = { {
        line = 2
      }, {
        line = 3
      } },
    lines = { 2, 3 },
    source = {
      name = "Program.cs",
      path = "/path/to/testDap/Program.cs"
    },
    sourceModified = false
  },
  command = "setBreakpoints",
  seq = 2,
  type = "request"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1742 ]    "request"   {
  arguments = {
    name = "launch - netcoredbg",
    program = "/path/to/testDap/bin/Debug/net8.0/testDap.dll",
    request = "launch",
    type = "coreclr"
  },
  command = "launch",
  seq = 3,
  type = "request"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1009 ]    1   {
  body = {
    breakpoints = { {
        id = 1,
        line = 2,
        message = "The breakpoint is pending and will be resolved when debugging starts.",
        verified = false
      }, {
        id = 2,
        line = 3,
        message = "The breakpoint is pending and will be resolved when debugging starts.",
        verified = false
      } }
  },
  command = "setBreakpoints",
  request_seq = 2,
  seq = "4",
  success = true,
  type = "response"
}
[ INFO ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:946 ]  "Breakpoint unverified" {
  id = 1,
  line = 2,
  message = "The breakpoint is pending and will be resolved when debugging starts.",
  verified = false
}
[ INFO ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:946 ]  "Breakpoint unverified" {
  id = 2,
  line = 3,
  message = "The breakpoint is pending and will be resolved when debugging starts.",
  verified = false
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1742 ]    "request"   {
  arguments = {
    filters = {}
  },
  command = "setExceptionBreakpoints",
  seq = 4,
  type = "request"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1009 ]    1   {
  body = vim.empty_dict(),
  command = "launch",
  request_seq = 3,
  seq = "5",
  success = true,
  type = "response"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1009 ]    1   {
  body = vim.empty_dict(),
  command = "setExceptionBreakpoints",
  request_seq = 4,
  seq = "6",
  success = true,
  type = "response"
}
[ DEBUG ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1742 ]    "request"   {
  command = "configurationDone",
  seq = 5,
  type = "request"
}
[ INFO ] 2024-09-18T11:23:21Z+0200 ] ...stDap/.repro/data/nvim/lazy/nvim-dap/lua/dap/session.lua:1482 ] "Process closed"    88276
mfussenegger commented 1 day ago

I'm afraid you'll have to report that upstream in the netcoredbg repo.

All the client can do is send the info about the breakpoints to the debug adapter - which according to the log is happening - and then it relies on the debug adapter to handle them, stop if they're hit, and send the corresponding events.

axelhj commented 1 day ago

Hi! I found (back in october) that netcoredbg under nvim-dap was sensitive to the :set noshellslash-option on windows. If the option was set, nvim would report paths with / rather than \. It would not match the paths that netcoredbg expected since it does not normalize those in the debugger.

I found this through experimenting, it was not really obvious that the shellslash option would have that effect. Maybe that helps (probably not if you're not on Windows).

Regards

Rekwass commented 1 day ago

Hello, thank you for you response, I saw this option and did not bother trying as I am on MacOS. I gave it a shot but unfortunately I run into the same issue.