0

I am trying to configure neovim with nvim-dap to debug C++ code. I was thinking about using the codelldb debugger, so I installed it via Mason

My configuration looks like this:

local dap = require("dap")
dap.configurations.cpp = {
    {
        name = "Debug using codelldb",
        type = "codelldb",
        request = "launch",
        program = function()
            return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
        end,
        cwd = "${workspaceFolder}",
        stopAtEntry = true,
    },
}


local mason_registry = require("mason-registry")
local codelldb = mason_registry.get_package("codelldb")
local codelldb_path = codelldb:get_install_path() .. "/extension/lldb/bin/lldb"

dap.adapters.codelldb = {
    id = "codelldb",
    type = "executable",
    command = codelldb_path,
}

The problem is that once I try to debug a program, I get the following message:

Debug adapter didn't respond. Either the adapter is slow (then wait and ignore this) or there is a problem with your adapter or lldb configuration. Check the logs for errors (:help dap.set_log_level)

Inside the log I have this:


[
  [ ERROR ] 2023-09-12T18:43:54Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1426 ] "stderr" {
    command = "/home/soestilooo/.local/share/nvim/mason/packages/codelldb/extension/lldb/bin/lldb",
    id = "codelldb",
    type = "executable"
  } "error: 'Content-Length' is not a valid command.\n"

  [ ERROR ] 2023-09-12T18:44:03Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1426 ] "stderr" {
    command = "/home/soestilooo/.local/share/nvim/mason/packages/codelldb/extension/lldb/bin/lldb",
    id = "codelldb",
    type = "executable"
  } "error: '{"arguments":{"pathFormat":"path","columnsStartAt1":true,"linesStartAt1":true,"supportsRunInTerminalRequest":true,"supportsVariableType":true,"supportsProgressReporting":true,"supportsStartDebuggingRequest":true,"locale":"en_US.UTF-8","clientId":"neovim","clientname":"neovim","adapterID":"codelldb"},"type":"request","command":"initialize","seq":0}Content-Length:' is not a valid command.\n"

  [ INFO ] 2023-09-12T18:44:06Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1779 ] "Session closed due to disconnect"

  [ ERROR ] 2023-09-12T18:44:06Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1426 ] "stderr" {
    command = "/home/soestilooo/.local/share/nvim/mason/packages/codelldb/extension/lldb/bin/lldb",
    id = "codelldb",
    type = "executable"
  } "error: '{"arguments":{"restart":false,"terminateDebuggee":true},"type":"request","command":"disconnect","seq":1}' is not a valid command.\n"

  [ ERROR ] 2023-09-12T18:56:53Z+0100 ] ...nvim/site/pack/packer/start/nvim-dap/lua/dap/session.lua:1426 ] "stderr" {
    command = "/home/soestilooo/.local/share/nvim/mason/packages/codelldb/extension/adapter/codelldb",
    id = "codelldb",
    type = "executable"
  } 'Error: "Either --connect or --port must be specified"\n'
]


Which I don't really understand :/

Please help me figure out what is the problem here, I tried making my configuration as simple as possible so it wouldn't cause any errors.

Thanks for all the feedback!

1 Answer 1

0

I use this configuration in rust, maybe it'll help you

local dap = require('dap')
local mason_registry = require("mason-registry")
local codelldb_root = mason_registry.get_package("codelldb"):get_install_path() .. "/extension/"
local codelldb_path = codelldb_root .. "adapter/codelldb"
local liblldb_path = codelldb_root .. "lldb/lib/liblldb.so"
dap.adapters.rust = {
  type = "server",
  port = "${port}",
  host = "127.0.0.1",
  executable = {
    command = codelldb_path,
    args = { "--liblldb", liblldb_path, "--port", "${port}" },
  },
}

https://github.com/simrat39/rust-tools.nvim/blob/0cc8adab23117783a0292a0c8a2fbed1005dc645/lua/rust-tools/dap.lua#L8C1-L18C4

https://www.reddit.com/r/rust/comments/zhokwt/share_your_neovim_setup_rusttools_nvimdap/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.