I just saw that there is now a plugin for nixvim dap
called dap-lldb
, which should make it easier to setup debug configurations for C/C++/Rust
.
My setup so far looked something like this:
{ config
, lib
, pkgs
, ...
}:
let
codelldb-config = {
name = "Launch (CodeLLDB)";
type = "codelldb";
request = "launch";
program.__raw = ''
function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', "file")
end
'';
cwd = ''''${workspaceFolder}'';
stopOnEntry = false;
};
lldb-config = {
name = "Launch (LLDB)";
type = "lldb";
request = "launch";
program.__raw = ''
function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. '/', "file")
end'';
cwd = ''''${workspaceFolder}'';
stopOnEntry = false;
};
in
{
extraPackages = with pkgs;
[
coreutils
lldb_18
];
plugins = {
dap = {
enable = true;
adapters = {
executables = {
lldb = {
command = lib.getExe' pkgs.lldb "lldb-vscode";
};
};
servers = {
codelldb = {
port = 13000;
executable = {
command = "${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb";
args = [
"--port"
"13000"
];
};
};
};
};
configurations = {
c = [ lldb-config ];
cpp =
[ lldb-config ]
++ lib.optionals pkgs.stdenv.isLinux [
codelldb-config
];
rust =
[ lldb-config ]
++ lib.optionals pkgs.stdenv.isLinux [
codelldb-config
];
};
extensions = {
dap-ui = {
enable = true;
};
dap-virtual-text = {
enable = false;
};
};
};
}
This worked okey-ish, but was a bit cumbersome. So the idea was to switch now to this plugging which hopefully should make this easier. The documentation can be found here and I guess the interesting part is also this subpage.
To be honest, Im not entirely sure how to use this plugin correctly… I tried the following:
{ config
, lib
, pkgs
, ...
}:
{
extraPackages = with pkgs;
[
coreutils
lldb_18
];
plugins = {
dap = {
enable = true;
adapters = {
executables = {
lldb = {
command = lib.getExe' pkgs.lldb "lldb-vscode";
};
};
servers = {
codelldb = {
port = 13000;
executable = {
command = "${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb";
args = [
"--port"
"13000"
];
};
};
};
};
configurations = {
};
extensions = {
dap-ui = {
enable = true;
};
dap-virtual-text = {
enable = false;
};
};
};
dap-lldb = {
enable = true;
settings.configurations = {
rust = [
{
cwd = "$\${workspaceFolder}";
name = "Debug";
program = {
__raw = ''
function(selection)
local targets = list_targets(selection)
if targets == nil then
return nil
end
if #targets == 0 then
return read_target()
end
if #targets == 1 then
return targets[1]
end
local options = { "Select a target:" }
for index, target in ipairs(targets) do
local parts = vim.split(target, sep, { trimempty = true })
local option = string.format("%d. %s", index, parts[#parts])
table.insert(options, option)
end
local choice = vim.fn.inputlist(options)
return targets[choice]
end
'';
};
request = "launch";
stopOnEntry = false;
type = "lldb";
}
]
}
};
};
}
but:
- This does not work. Trying to run a Rust application with the debugger results in a complaint that I need to register a
dap.configurations.rust
entry, and - This does not seem to be much more simple than writing in the original way…
So, in short, how would a correct example config look like for dap-lldb
?