mfussenegger / nvim-dap

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

Gdb error after following debug adapter installation wiki #1308

Closed thomascookandroid closed 3 months ago

thomascookandroid commented 3 months ago

Debug adapter definition and debug configuration

return {
    "mfussenegger/nvim-dap",
    dependencies = {
        "rcarriga/nvim-dap-ui",
        "nvim-neotest/nvim-nio"
    },
    config = function ()
        local nvim_dap = require("dap")
        local nvim_dap_ui = require("dapui")
        nvim_dap_ui.setup()
        nvim_dap.listeners.before.attach.dapui_config = function ()
            nvim_dap_ui.open()
        end
        nvim_dap.listeners.before.launch.dapui_config = function ()
            nvim_dap_ui.open()
        end
        nvim_dap.listeners.before.event_terminated.dapui_config = function ()
            nvim_dap_ui.close()
        end
        nvim_dap.listeners.before.event_exited.dapui_config = function ()
            nvim_dap_ui.close()
        end
        nvim_dap.adapters.gdb = {
            type = "executable",
            command = "gdb",
            args = {
                "--interpreter=dap",
                "--eval-commmand",
                "set logging enabled on"
            }
        }
        nvim_dap.configurations.c = {
            {
                name = "Launch",
                type = "gdb",
                request = "launch",
                cwd = "${workspaceFolder}",
                program = function ()
                    return vim.fn.input(
                        "Path to executable: ",
                        vim.fn.getcwd() .. "/bin/",
                        "file"
                    )
                end,
                stopAtBeginningOfMainSubprogram = false
            }
        }
    end
}

Debug adapter version

Not sure how to determine

Steps to Reproduce

  1. Install gdb 15.1
  2. Write some simple hello world C program:
    
    #include <stdio.h>

int main(void) { printf("To C, or not to C: that is the question.\n"); return 0; }


3. Run `DapToggleBreakpoint` to set a breakpoint on a line in the c code
4. Compile the c code: `gcc -o bin/pun pun.c`
5. Run `DapContinue` and point it at the executable
6. Observe error `gdb exited with code: 1`

### Expected Result

Following the debug adapter wiki, which tells user to use gdb 14.0+ should not result in an error

### Actual Result

Following the debug adapter wiki, which tells user to use gdb 14.0+ results in an error: `gdb exited with code: 1`
mfussenegger commented 3 months ago

Check the logs and make sure you're using a gdb variant that includes dap support. Some distributions strip it out.

thomascookandroid commented 3 months ago

I have just built gdb 14.1 from source. That has DAP support, and yet this issue persists. In addition, no log file is getting generated in the working directory, even though I supply "--eval-command=set logging enabled", so I have no way to provide further information.

Is there any advice you can give me on how to proceed?

thomascookandroid commented 3 months ago
gdb --ver
GNU gdb (GDB) 14.1
thomascookandroid commented 3 months ago

I found the nvim-dap logs which shows that there was an error:

[ ERROR ] 2024-08-08T11:43:13Z+0100 ] ...omas/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1466 ]    "stderr"    {
  args = { "--interpreter=dap", "--eval-command=set logging enabled on" },
  command = "gdb",
  type = "executable"
}   "Interpreter `dap' unrecognized\n"

The error is stating that gdb is reporting Interpreter 'dap' unrecognised....

Does this mean the gdb variant I have made from source and installed does not support DAP? From all the reading I have done, 14.1 was the version of gdb that actually added DAP support...

Please advise

mfussenegger commented 3 months ago

The error is stating that gdb is reporting Interpreter 'dap' unrecognised....

Does this mean the gdb variant I have made from source and installed does not support DAP?

Yes that's what it means

From all the reading I have done, 14.1 was the version of gdb that actually added DAP support...

It added DAP support but the feature is optional and can be excluded. You need to make sure to use a build that includes it.

thomascookandroid commented 3 months ago

I see, apologies. Should have RTFM