aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/home/.config/nvim/lua/plugins/debug.lua
blob: bef0d1c740a61099c47bde62cf0ccd513e8bed7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
vim.keymap.set("n", "<leader>td", function()
  require("debugmaster").mode.toggle()
end, { desc = "[T]oggle [D]ebug mode" })

local dap = require("dap")

local function get_env_vars()
  local variables = vim.fn.environ()
  table.insert(variables, { ASAN_OPTIONS = "detect_leaks=0" })
  return variables
end

dap.adapters.lldb = {
  type = "executable",
  command = "lldb-dap",
  name = "lldb",
  env = get_env_vars,
}
dap.adapters.gdb = {
  type = "executable",
  command = "gdb",
  args = { "--interpreter=dap" },
  env = get_env_vars,
}
dap.adapters.codelldb = {
  type = "executable",
  command = "codelldb",
  env = get_env_vars,
}

local function get_program()
  local _program
  vim.ui.input({
    prompt = "Program: ",
    complete = "file_in_path",
  }, function(res)
    _program = res
  end)
  return vim.fn.system("which " .. _program):gsub("\n$", "")
end

local function get_args()
  local _args
  vim.ui.input({
    prompt = "Args: ",
    default = vim.fn.getreg("+"),
    complete = "file",
  }, function(res)
    _args = res
  end)
  return require("dap.utils").splitstr(_args)
end

dap.configurations.cpp = {
  {
    name = "codelldb Launch",
    type = "codelldb",
    request = "launch",
    cwd = "${workspaceFolder}",
    program = get_program,
    args = get_args,
    stopOnEntry = true,
    console = "integratedTerminal",
  },
}

dap.configurations.c = dap.configurations.cpp
dap.configurations.rust = dap.configurations.cpp

require("nvim-dap-virtual-text").setup({})
require("mason-nvim-dap").setup({
  automatic_installation = false,
  handlers = {},
  ensure_installed = {},
})