local dap = require("dap")
local cmd = os.getenv('HOME') .. '/tool/debug/codelldb/adapter/codelldb'
dap.adapters.codelldb = function(on_adapter)
-- This asks the system for a free port
local tcp = vim.loop.new_tcp()
tcp:bind('127.0.0.1', 0)
local port = tcp:getsockname().port
tcp:shutdown()
tcp:close()
-- Start codelldb with the port
local stdout = vim.loop.new_pipe(false)
local stderr = vim.loop.new_pipe(false)
local opts = {
stdio = {nil, stdout, stderr},
args = {'--port', tostring(port)},
}
local handle
local pid_or_err
handle, pid_or_err = vim.loop.spawn(cmd, opts, function(code)
stdout:close()
stderr:close()
handle:close()
if code ~= 0 then
print("codelldb exited with code", code)
end
end)
if not handle then
vim.notify("Error running codelldb: " .. tostring(pid_or_err), vim.log.levels.ERROR)
stdout:close()
stderr:close()
return
end
vim.notify('codelldb started. pid=' .. pid_or_err)
stderr:read_start(function(err, chunk)
assert(not err, err)
if chunk then
vim.schedule(function()
require("dap.repl").append(chunk)
end)
end
end)
local adapter = {
type = 'server',
host = '127.0.0.1',
port = port
}
--
标签:function,end,vim,dap,codelldb,local,nvim
From: https://www.cnblogs.com/Searchor/p/17277235.html