2021-02-25 16:06:52 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- - NeoVim DAP (Debug Adapter Protocol) config -
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
2021-12-02 15:12:10 +00:00
|
|
|
local dap = require("dap")
|
|
|
|
local dap_install = require("dap-install")
|
2021-02-25 16:06:52 +00:00
|
|
|
|
2021-11-05 09:56:28 +00:00
|
|
|
local dbg_list = require("dap-install.api.debuggers").get_installed_debuggers()
|
2021-02-25 16:06:52 +00:00
|
|
|
|
2021-11-05 09:56:28 +00:00
|
|
|
for _, debugger in ipairs(dbg_list) do
|
2021-12-02 15:12:10 +00:00
|
|
|
dap_install.config(debugger)
|
2021-11-05 09:56:28 +00:00
|
|
|
end
|
2021-06-11 11:00:32 +00:00
|
|
|
|
2021-11-05 09:56:28 +00:00
|
|
|
vim.cmd [[ au FileType dap-repl lua require('dap.ext.autocompl').attach() ]]
|
2021-06-11 11:00:32 +00:00
|
|
|
|
2021-02-25 16:06:52 +00:00
|
|
|
-- Nvim DAP Treesitter integration
|
2021-11-05 09:56:28 +00:00
|
|
|
require("nvim-dap-virtual-text").setup()
|
2021-03-03 17:07:02 +00:00
|
|
|
|
|
|
|
-- Keymaps
|
2021-12-02 15:12:10 +00:00
|
|
|
local function set_keymap(...)
|
|
|
|
vim.api.nvim_set_keymap(...)
|
|
|
|
end
|
2021-03-03 17:07:02 +00:00
|
|
|
|
2021-03-09 17:39:56 +00:00
|
|
|
local default_opts = {noremap = true, silent = true}
|
2021-12-02 15:12:10 +00:00
|
|
|
set_keymap("n", "<Leader>db", "<cmd>lua require'dap'.toggle_breakpoint()<CR>", default_opts)
|
|
|
|
set_keymap("n", "<Leader>dc", "<cmd>lua require'dap'.continue()<CR>", default_opts)
|
|
|
|
set_keymap("n", "<Leader>dso", "<cmd>lua require'dap'.step_over()<CR>", default_opts)
|
|
|
|
set_keymap("n", "<Leader>dsi", "<cmd>lua require'dap'.step_into()<CR>", default_opts)
|
|
|
|
set_keymap("n", "<Leader>dro", "<cmd>lua require'dap'.open()<CR>", default_opts)
|
2021-03-03 17:07:02 +00:00
|
|
|
|
2021-11-05 09:56:28 +00:00
|
|
|
-- Nvim DAP UI
|
2022-03-23 10:40:13 +00:00
|
|
|
local dapui = require("dapui")
|
|
|
|
dapui.setup()
|
2021-11-05 09:56:28 +00:00
|
|
|
|
2021-03-03 17:07:02 +00:00
|
|
|
-- Debugger Hover map
|
|
|
|
local api = vim.api
|
|
|
|
local keymap_restore = {}
|
2021-12-02 15:12:10 +00:00
|
|
|
dap.listeners.after["event_initialized"]["me"] = function()
|
|
|
|
for _, buf in pairs(api.nvim_list_bufs()) do
|
|
|
|
local keymaps = api.nvim_buf_get_keymap(buf, "n")
|
|
|
|
for _, keymap in pairs(keymaps) do
|
|
|
|
if keymap.lhs == "K" then
|
|
|
|
table.insert(keymap_restore, keymap)
|
|
|
|
api.nvim_buf_del_keymap(buf, "n", "K")
|
|
|
|
end
|
|
|
|
end
|
2021-03-03 17:07:02 +00:00
|
|
|
end
|
2021-12-02 15:12:10 +00:00
|
|
|
api.nvim_set_keymap("n", "K", '<Cmd>lua require("dap.ui.variables").hover()<CR>', {silent = true})
|
2021-03-03 17:07:02 +00:00
|
|
|
end
|
|
|
|
|
2021-12-02 15:12:10 +00:00
|
|
|
dap.listeners.after["event_terminated"]["me"] = function()
|
|
|
|
for _, keymap in pairs(keymap_restore) do
|
|
|
|
api.nvim_buf_set_keymap(keymap.buffer, keymap.mode, keymap.lhs, keymap.rhs, {silent = keymap.silent == 1})
|
|
|
|
end
|
|
|
|
keymap_restore = {}
|
2021-03-03 17:07:02 +00:00
|
|
|
end
|
2022-03-23 10:40:13 +00:00
|
|
|
|
|
|
|
-- Additional servers
|
|
|
|
dap.adapters.lldb = {
|
|
|
|
type = "executable",
|
|
|
|
command = "lldb-vscode",
|
|
|
|
name = "lldb"
|
|
|
|
}
|
|
|
|
|
|
|
|
dap.configurations.cpp = {
|
|
|
|
{
|
|
|
|
name = "Launch",
|
|
|
|
type = "lldb",
|
|
|
|
request = "launch",
|
|
|
|
program = function()
|
|
|
|
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
|
|
|
|
end,
|
|
|
|
cwd = "${workspaceFolder}",
|
|
|
|
stopOnEntry = false,
|
|
|
|
args = {},
|
|
|
|
-- 💀
|
|
|
|
-- 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 = false,
|
|
|
|
-- 💀
|
|
|
|
-- If you use `runInTerminal = true` and resize the terminal window,
|
|
|
|
-- lldb-vscode will receive a `SIGWINCH` signal which can cause problems
|
|
|
|
-- To avoid that uncomment the following option
|
|
|
|
-- See https://github.com/mfussenegger/nvim-dap/issues/236#issuecomment-1066306073
|
|
|
|
postRunCommands = {"process handle -p true -s false -n false SIGWINCH"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dap.configurations.c = dap.configurations.cpp
|
|
|
|
dap.configurations.rust = dap.configurations.cpp
|
|
|
|
|
|
|
|
dap.listeners.after.event_initialized["dapui_config"] = function()
|
|
|
|
dapui.open()
|
|
|
|
end
|
|
|
|
dap.listeners.before.event_terminated["dapui_config"] = function()
|
|
|
|
dapui.close()
|
|
|
|
end
|
|
|
|
dap.listeners.before.event_exited["dapui_config"] = function()
|
|
|
|
dapui.close()
|
|
|
|
end
|