summary refs log tree commit diff
path: root/.vim/lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2022-06-15 04:40:25 +0200
committerRobert Günzler <r@gnzler.io>2022-06-15 04:40:25 +0200
commit5d3c12f35fc1295032c494a14cf902ed091aeb89 (patch)
treee0677bcc823917bbe5131dd24d5899b790dde747 /.vim/lua
parentc41fa8be2cb3d86ca78e36fd7dca198e1b554520 (diff)
vim: add gdbserver configuration to DAP config
Diffstat (limited to '.vim/lua')
-rw-r--r--.vim/lua/debugger.lua36
1 files changed, 31 insertions, 5 deletions
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,