mfussenegger / nvim-dap

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

Cannot connect to gdbserver #1167

Closed PrettRett closed 4 months ago

PrettRett commented 4 months ago

Debug adapter definition and debug configuration

Installed the plugin using lazyvim, from what I've seen It should be the latest release.

The configuration is: `dap.adapters.gdb = { type="server", port="1234", -- type="executable", command = "gdb", args = {"-i", "dap"}, initialize_timeout_sec=30, }

dap.configurations.c = { { name = "Attacher", type = "gdb", request = "launch", cwd = "${workspaceFolder}", program = function () return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') end, }, }`

I've tested commenting type="server" and port="1234" and uncommenting the line type="executable", and I can successfully run the debug session, so at least I know the general configuration and version of GDB is working.

I've tested connecting to the gdbserver through the terminal and debugging using the gdb command "gdb --eval-command='target remote localhost:1234'" and it successfully connect to the gdbserver and I can debug, so I know that the server is running properly. The server is executed with the command: "gdbserver localhost:1234 /path/to/executable"

When I try to start the debug session, the meesage it appears is: image

And the debug information for the request call is: image

Debug adapter version

No response

Steps to Reproduce

  1. Configure the dap to connect to a server
  2. Execute the server in another terminal
  3. Try to start the debug session

Expected Result

Starts the debug session, or it responds with an error message

Actual Result

The Debug adapter didn't respond message appears and every command we attempt to the dap this message appears: image

The message seen from the gdbserver are: image

mfussenegger commented 4 months ago

The server type is for debug adapters that communicate via TCP with the client(=nvim-dap) . That's not the case with gdb -i dap, which uses stdio.

You need to use the executable type for gdb itself:

dap.adapters.gdb = {
  type = "executable",
  command = "gdb",
  args = { "-i", "dap" }
}

And then an attach configuration, to tell that gdb should connect to the gdbserver:

dap.configurations.c = {
  {
    name = "gdbserver: attach",
    type = "gdb",
    request = "attach",
    target = "localhost:1234",
    cwd = '${workspaceFolder}',
  },
}

So the communication is:

  ┌──────────┐ DAP ┌─────┐        ┌──────────┐       ┌───────────────┐
  │ nvim-dap │────►│ gdb │───────►│ gdbserver│──────►│your-executable│
  └──────────┘     └─────┘        └──────────┘       └───────────────┘
PrettRett commented 4 months ago

Thank you!!