mfussenegger / nvim-dap

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

Error on attach: can't parse: [json.exception.out_of_range.403] key 'processId' not found #356

Closed MikaelElkiaer closed 2 years ago

MikaelElkiaer commented 2 years ago

Debug adapter definition and debug configuration

dap.adapters.netcoredbg = function(cb, config)
  if config.preLaunchTask then config.preLaunchTask() end
  local adapter = {
    type = 'executable',
    command = '/usr/bin/netcoredbg',
    args = {'--interpreter=vscode'}
  }
  cb(adapter)
end
dap.configurations.cs = {
  {
    type = "netcoredbg",
    name = "launch - netcoredbg",
    request = "attach",
    pid = function()
      local pgrep = vim.fn.system("pgrep -f 'dotnet run --project Beehive'")
      return tonumber(pgrep)
    end,
    preLaunchTask = function()
      Term = vim.fn.termopen("dotnet run --project Beehive")
    end
  },
}

Debug adapter version

No response

Steps to Reproduce

I am trying to run the above config in a simple .NET Core project: https://github.com/MikaelElkiaer/Beehive

Using the config above I try to start debugging via lua require'dap'.continue().

Expected Result

No error like the one in title.

Actual Result

I see Error on attach: can't parse: [json.exception.out_of_range.403] key 'processId' not found.

I get the same error if I try an even simpler config with pid = require('dap.utils').pick_process and without the preLaunchTask.

I have little to no idea how to provide more info, but if you could point me in the right direction I'd be happy to provide more info.

mfussenegger commented 2 years ago

Based on the error message I'd guess that netcoredbg requires a property named processId, not pid. So maybe this works?

dap.configurations.cs = {
  {
    type = "netcoredbg",
    name = "launch - netcoredbg",
    request = "attach",
    processId = function()
      local pgrep = vim.fn.system("pgrep -f 'dotnet run --project Beehive'")
      return tonumber(pgrep)
    end,
    preLaunchTask = function()
      Term = vim.fn.termopen("dotnet run --project Beehive")
    end
  },
}
MikaelElkiaer commented 2 years ago

That changed nothing.

I actually though it might have something to do with one of these: https://github.com/mfussenegger/nvim-dap/blob/4e8bb7ca12dc8ca6f7a500cbb4ecea185665c7f1/lua/dap/session.lua#L96 https://github.com/mfussenegger/nvim-dap/blob/4e8bb7ca12dc8ca6f7a500cbb4ecea185665c7f1/lua/dap/session.lua#L142

MikaelElkiaer commented 2 years ago

It seems like there is some dynamic link between the dap configuration and the adapter that I don't understand. netcoredbg has a paramater --attach where I can supply the process ID. How does this map to the config?

mfussenegger commented 2 years ago

Are you sure that pgrep is returning something? You can check the log to see what's sent to the adapter (See :h dap.set_log_level)

The error message can't parse: [json.exception.out_of_range.403] key 'processId' not found is definitely coming from the adapter.

The other two processId places you linked are unrelated.

MikaelElkiaer commented 2 years ago

Ok, you were right in setting the processId. Got further by dropping my preLaunchTask and instead manually starting the program, and then only using the processId function to get the pid. However, this just lead me to a new issue: The breakpoint is pending and will be resolved when debugging starts.

I will dig deeper another day. Here are some fun debug output though, as I am seeing a lot of these and it is probably a symptom of whatever is wrong:

[ DEBUG ] 2021-11-23T00:03:21Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:536 ] {
  body = {
    module = {
      id = "e6de5815-2070-4ff5-948f-2fde01972daa",
      name = "System.Private.CoreLib.dll",
      path = "/opt/dotnet/shared/Microsoft.NETCore.App/3.1.18/System.Private.CoreLib.dll",
      symbolStatus = "Symbols not found."
    },
    reason = "new"
  },
  event = "module",
  seq = 8,
  type = "event"
}
mfussenegger commented 2 years ago

Are you using a debug build that has the debug symbols?

MikaelElkiaer commented 2 years ago

Are you using a debug build that has the debug symbols?

I am fairly sure that I am. I can get it to work if I do a configuration with a request type of 'launch' instead of 'attach'. Not at all sure what I am missing for attaching properly.

MikaelElkiaer commented 2 years ago

I finally got further.

Seems that starting a dotnet application with dotnet run --project Beehive did not work properly. But start it with dotnet Beehive/bin/Debug/netcoreapp3.1/Beehive.dll did.

Leaving this comment for others to find, and then I will close it.

Edit: Seems like I was attaching to the wrong process - the dotnet run, instead of its subprocess which was the actual program.