mfussenegger / nvim-dap

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

require('dap').run_last() does not work correctly #1101

Closed rileychc closed 10 months ago

rileychc commented 10 months ago

Debug adapter definition and debug configuration

local dap = require("dap")

local utils = require("modules.utils.dap")

dap.adapters.lldb = {
    type = "executable",
    command = vim.fn.exepath("lldb-vscode"), -- Find lldb-vscode on $PATH
}

local function get_program_path()
    -- local recent_projects = require("project_nvim").get_recent_projects() --project.nvim
    -- local current_directory_name = vim.fn.fnamemodify(current_directory, ":t")
    local current_file = vim.fn.expand("%:p")
    local cwd = vim.fn.getcwd()
    local current_directory = vim.fn.fnamemodify(current_file, ":h")
    current_directory = current_directory:gsub("[\\/]+$", "")
    local parent_directory = vim.fn.fnamemodify(current_directory, ":h")
    parent_directory = parent_directory:gsub("[\\/]+$", "")
    local grandparent_directory = vim.fn.fnamemodify(parent_directory, ":h")
    grandparent_directory = grandparent_directory:gsub("[\\/]+$", "")

    local split_path = vim.split(cwd, "/")
    local project_name = split_path[#split_path]
    local current_filename = vim.fn.fnamemodify(current_file, ":t:r")
    if cwd == "/Users/demo/Algorithm/Leetcode" then
        return vim.fn.input("Path to executable: ", current_directory .. "/bin/" .. "solution.out", "file")
    end
    if string.find(current_directory, "/Users/demo/Project") then
        return vim.fn.input(
            "Path to executable: ",
            cwd .. "/build/" .. project_name .. ".app/Contents/MacOS/" .. project_name,
            "file"
        )
    else
        return vim.fn.input(
            "Path to executable: ",
            current_directory .. "/bin/" .. current_filename .. ".out",
            "file"
        )
    end
end
dap.configurations.cpp = {
    {
        name = "Launch",
        type = "lldb",
        request = "launch",
        -- program = utils.input_exec_path(),
        cwd = "${workspaceFolder}",
        -- args = utils.input_args(),
        env = utils.get_env(),

        program = function()
            return get_program_path()
        end,

        -- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
        --
        --    echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
        --
        -- Otherwise you might get the following error:
        --
        --    Error on launch: Failed to attach to the target process
        --
        -- But you should be aware of the implications:
        -- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
        runInTerminal = true,
    },
}

Debug adapter version

No response

Steps to Reproduce

1.Debug c++ programs using vscode-lldb 2.Set breakpoints and debug and test c++ programs 3.Run the command lua require('dap').run_last()

Expected Result

Work correctly

Actual Result

E5108: Error executing lua: ....local/share/nvim/site/lazy/nvim-dap/lua/dap/session.lua:78: Cannot serialise function: type not supported stack traceback: [C]: in function 'json_encode' ....local/share/nvim/site/lazy/nvim-dap/lua/dap/session.lua:78: in function 'send_payload' ....local/share/nvim/site/lazy/nvim-dap/lua/dap/session.lua:1694: in function 'request' ...s/riley/.local/share/nvim/site/lazy/nvim-dap/lua/dap.lua:741: in function 'restart' ...s/riley/.local/share/nvim/site/lazy/nvim-dap/lua/dap.lua:471: in function 'run' ...s/riley/.local/share/nvim/site/lazy/nvim-dap/lua/dap.lua:526: in function 'run_last' /Users/riley/.config/nvim/lua/keymap/tool.lua:186: in function </Users/riley/.config/nvim/lua/keymap/tool.lua:185>

mfussenegger commented 10 months ago

Could you try with https://github.com/mfussenegger/nvim-dap/pull/1103?

rileychc commented 10 months ago

Could you try with #1103?

Thanks u !