summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2022-07-01 16:59:25 +0200
committerRobert Günzler <r@gnzler.io>2022-08-02 22:13:49 +0200
commitbfc89865e1894f8aef60cc3c9bbde9f22b228ca1 (patch)
tree49fbd8858065ba2eff4c575c17ce416b81c1f3c4
parente54f2e4830eedb0930ccb3b5fdb8cffe8b9e8dbf (diff)
vim: use lldb for debugging c/cpp/rust
-rw-r--r--.vim/lua/debugger.lua155
1 files changed, 97 insertions, 58 deletions
diff --git a/.vim/lua/debugger.lua b/.vim/lua/debugger.lua
index 32b75b5..7b1ad2c 100644
--- a/.vim/lua/debugger.lua
+++ b/.vim/lua/debugger.lua
@@ -1,7 +1,15 @@
+-- vim: fdm=marker
+
 require('telescope').load_extension('dap')
 
 local dap = require('dap')
 dap.defaults.fallback.terminal_win_cmd = 'belowright 10new'
+dap.defaults.fallback.terminal_win_cmd = 'belowright 10new'
+
+-- open repl when session starts
+dap.listeners.after['event_initialized']['me'] = function()
+  dap.repl.toggle()
+end
 
 -- signs
 vim.fn.sign_define({{name='DapBreakpoint', text='🞱', texthl='DapBreakpoint', linehl='DapBreakpointLn'}})
@@ -38,8 +46,17 @@ wk_register {
     B = {'list_breakpoints'}
   }
 }
--- ADAPTERS
 
+-- Common
+local bin_from_var_or_pick = function()
+  local ok, retval = pcall(vim.api.nvim_buf_get_var, 0, 'dap_bin')
+  if ok then return retval end
+  local bin = nil
+  vim.ui.input({prompt = 'DAP Binary: '}, function(choice) bin = choice end)
+  return bin
+end
+
+-- Go {{{
 dap.adapters.go_dlv_local = function(callback, config) -- {{{
   local stdout = vim.loop.new_pipe()
   local handle
@@ -69,57 +86,6 @@ dap.adapters.go_dlv_remote = {
   port = 38697,
 }
 
-dap.adapters.cppdbg = {
-  id = 'cppdbg',
-  type = 'executable',
-  command = vim.env.HOME .. '/.local/share/nvim/dap/ms-vscode.cpptools/extension/debugAdapters/bin/OpenDebugAD7',
-}
-
--- CONFIGURATIONS
-
-dap.configurations.c = {
-  {
-    name = 'Launch binary',
-    type = 'cppdbg',
-    request = 'launch',
-    program = function()
-      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 = {
   {
     name = 'Debug (local)',
@@ -132,11 +98,84 @@ dap.configurations.go = {
     type = 'go_dlv_remote',
     request = 'launch',
     mode = 'exec',
-    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,
+    program = bin_from_var_or_pick,
   },
 }
+-- end of Go }}}
+
+-- C/C++/Rust {{{
+-- dap.adapters.cppdbg = {
+--   id = 'cppdbg',
+--   type = 'executable',
+--   command = vim.env.HOME .. '/.local/share/nvim/dap/ms-vscode.cpptools/extension/debugAdapters/bin/OpenDebugAD7',
+-- }
+dap.adapters.lldb = {
+  type = 'executable',
+  command = vim.trim(vim.fn.system('command -v lldb-vscode')),
+  name = 'lldb',
+}
+
+-- dap.configurations.c = {
+--   {
+--     name = 'Launch binary',
+--     type = 'cppdbg',
+--     request = 'launch',
+--     program = function()
+--       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.c = {
+  {
+    name = 'Launch',
+    type = 'lldb',
+    request = 'launch',
+    program = bin_from_var_or_pick,
+    args = {},
+    cwd = '${workspaceFolder}',
+    stopOnEntry = false,
+  },
+  {
+    name = 'Attach',
+    type = 'lldb',
+    request = 'attach',
+    pid = require('dap.utils').pick_process,
+    args = {},
+  },
+}
+dap.configurations.cpp = dap.configurations.c
+dap.configurations.rust = dap.configurations.c
+
+-- end of C/C++/Rust }}}