mfussenegger / nvim-dap

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

pick_files() doesn't work on neovim 0.10 #1220

Closed cryptomilk closed 1 month ago

cryptomilk commented 1 month ago

Debug adapter definition and debug configuration

pick_files only gives me an empty list:

local ok, dap = pcall(require, 'dap')
if not ok then
    return
end

local dap_utils = require('dap.utils')

local cwd = vim.fn.getcwd()
local is_samba = cwd:find('samba')

local path = cwd
if is_samba then
    path = cwd .. '/bin'
end

local exec_opts = {
    path = path,
    executables = true,

    filter = function(exec)
        -- Filter out shared libraries
        return not exec:match('%.so([.0-9]*)')
    end,
}

--
-- See
-- https://sourceware.org/gdb/current/onlinedocs/gdb.html/Interpreters.html
-- https://sourceware.org/gdb/current/onlinedocs/gdb.html/Debugger-Adapter-Protocol.html
dap.adapters.gdb = {
    id = 'gdb',
    type = 'executable',
    command = 'gdb',
    args = { '--quiet', '--interpreter=dap' },
    --[[
    args = {
        '-iex',
        'set debug dap-log-file /tmp/gdb-dap.log',
        '--quiet',
        '--interpreter=dap',
    },
]

dap.configurations.c = {
    {
        name = 'Run executable (GDB)',
        type = 'gdb',
        request = 'launch',
        -- This requires special handling of 'run_last', see
        -- https://github.com/mfussenegger/nvim-dap/issues/1025#issuecomment-1695852355
        program = function()
            return dap_utils.pick_file(exec_opts)
        end,
    },
    {
        name = 'Run executable with arguments (GDB)',
        type = 'gdb',
        request = 'launch',
        -- This requires special handling of 'run_last', see
        -- https://github.com/mfussenegger/nvim-dap/issues/1025#issuecomment-1695852355
        program = function()
            return dap_utils.pick_file(exec_opts)
        end,
        args = function()
            local args_str = vim.fn.input({
                prompt = 'Execeutable arguments: ',
            })
            return vim.split(args_str, ' +')
        end,
    },
    {
        name = 'Attach to process (GDB)',
        type = 'gdb',
        request = 'attach',
        processId = require('dap.utils').pick_process,
    },
}

Debug adapter version

master

Steps to Reproduce

  1. Open C file
  2. Set Breakpoint
  3. Try to run it with gdb config
  4. Get executable file list

Expected Result

Get a executable file list

Actual Result

Empty list

If I count the files it walks with vim.fs.dir(), I see it finds 14k files. If I set exeutables = false it works.

My lua-lanaguage server tells me:

local stat = uv.fs_stat(filepath)     ● Undefined field `fs_stat`.

If I add a bit of more debug:

check file: default/source4/dsdb/samdb/ldb_modules/tests/test_unique_object_sids.c.9.o
no stat

It looks like stat always fails.

mfussenegger commented 1 month ago

What permissions do the files have? It's currently checking for user-executable permission

fs_stat should definitely work, it is also used in the vscode launch.json logic and all over the neovim code base.

mfussenegger commented 1 month ago

Oh I think I know what's going on. fs_path receives relative paths, which it resolves based on cwd. With a custom path the filtering is therefore broken. I first had absolute paths but changed that to relative to have more readable output in the prompt.

I'll whip up a fix

mfussenegger commented 1 month ago

Can you try with https://github.com/mfussenegger/nvim-dap/pull/1221 ?