From 5d3c12f35fc1295032c494a14cf902ed091aeb89 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Wed, 15 Jun 2022 04:40:25 +0200 Subject: vim: add gdbserver configuration to DAP config --- .vim/lua/debugger.lua | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to '.vim/lua/debugger.lua') diff --git a/.vim/lua/debugger.lua b/.vim/lua/debugger.lua index 67fcf16..e847076 100644 --- a/.vim/lua/debugger.lua +++ b/.vim/lua/debugger.lua @@ -53,7 +53,7 @@ dap.adapters.go_dlv_local = function(callback, config) -- {{{ handle, pid_or_err = vim.loop.spawn("dlv", opts, function(exit) stdout:close() handle:close() - if exit ~= 0 then vim.notify('dlv exited with exit code ' .. code) end + if exit ~= 0 then vim.notify('dlv exited with exit code ' .. exit) end end) assert(handle, 'Error running dlv: ' .. tostring(pid_or_err)) stdout:read_start(function(err, chunk) @@ -72,7 +72,7 @@ dap.adapters.go_dlv_remote = { dap.adapters.cppdbg = { id = 'cppdbg', type = 'executable', - command = vim.env.HOME .. '/.local/share/nvim/dap/ms-vscode.cpptools-1.9.1@linux-x64/extension/debugAdapters/bin/OpenDebugAD7', + command = vim.env.HOME .. '/.local/share/nvim/dap/ms-vscode.cpptools/extension/debugAdapters/bin/OpenDebugAD7', } -- CONFIGURATIONS @@ -83,17 +83,42 @@ dap.configurations.c = { type = 'cppdbg', request = 'launch', program = function() - -- TODO assuming meson - return vim.trim(vim.fn.system( + local file = vim.g.dapbin + if file then return file end + -- TODO: assuming meson + file = vim.trim(vim.fn.system( [[jq -r '..|select(.type?=="executable")|.filename|.[0]' ]] .. vim.lsp.buf.list_workspace_folders()[1] .. [[/build/meson-info/intro-targets.json]] )) + local fd = vim.loop.fs_open(file, "r", 438) + if file and fd then + vim.loop.fs_close(fd) + return file + end + vim.ui.input('binary: ', function(result) file = result end) + return file end, cwd = '${workspaceFolder}', stopOnEntry = true, }, + { + name = 'Attach to gdbserver', + type = 'cppdbg', + request = 'launch', + MIMode = 'gdb', + miDebuggerServerAddress = 'localhost:1234', + miDebuggerPath = '/usr/bin/gdb', + cwd = '${workspaceFolder}', + program = function() + local file = vim.g.dapbin + if file then return file end + vim.ui.input('binary: ', function(result) file = result end) + return file + end, + }, } +dap.configurations.cpp = dap.configurations.c dap.configurations.go = { { @@ -108,7 +133,8 @@ dap.configurations.go = { request = 'launch', mode = 'exec', program = function() - local file + local file = vim.g.dapbin + if file then return file end vim.ui.input('binary: ', function(result) file = result end) return file end, -- cgit 1.4.1