|
| 1 | +-- This is an example of how to configure the DAP connection in an editor (neovim in this case) |
| 2 | +-- It should be relatively straightforward to adapt to a different editor |
| 3 | + |
| 4 | +local dap = require("dap") |
| 5 | +local job = require("plenary.job") |
| 6 | + |
| 7 | +-- This is a coroutine that runs the cargo build command and reports progress |
| 8 | +local program = function() |
| 9 | + return coroutine.create(function(dap_run_co) |
| 10 | + local progress = require("fidget.progress") |
| 11 | + |
| 12 | + local cargo_build_fidget = progress.handle.create({ |
| 13 | + title = "cargo build", |
| 14 | + lsp_client = { name = "Debugger" }, |
| 15 | + percentage = 0, |
| 16 | + }) |
| 17 | + |
| 18 | + local cargo_build_job = job:new({ |
| 19 | + command = "cargo", |
| 20 | + args = { "build", "--color=never", "--profile=dev" }, |
| 21 | + cwd = vim.fn.getcwd(), |
| 22 | + enable_handlers = true, |
| 23 | + on_stderr = vim.schedule_wrap(function(_, output) |
| 24 | + cargo_build_fidget:report({ |
| 25 | + message = output, |
| 26 | + percentage = cargo_build_fidget.percentage + 0.3, |
| 27 | + }) |
| 28 | + end), |
| 29 | + on_exit = function(_, return_val) |
| 30 | + vim.schedule(function() |
| 31 | + if return_val ~= 0 then |
| 32 | + cargo_build_fidget:report({ |
| 33 | + message = "Error during cargo build", |
| 34 | + percentage = 100, |
| 35 | + }) |
| 36 | + else |
| 37 | + cargo_build_fidget:finish() |
| 38 | + coroutine.resume(dap_run_co, vim.fn.getcwd() .. "/target/debug/bootc") |
| 39 | + end |
| 40 | + end) |
| 41 | + end, |
| 42 | + }) |
| 43 | + |
| 44 | + cargo_build_job:start() |
| 45 | + end) |
| 46 | +end |
| 47 | + |
| 48 | +dap.adapters = { |
| 49 | + lldb = { |
| 50 | + executable = { |
| 51 | + args = { |
| 52 | + "--liblldb", |
| 53 | + "~/.local/share/nvim/mason/packages/codelldb/extension/lldb/lib/liblldb.so", |
| 54 | + "--port", |
| 55 | + "${port}", |
| 56 | + }, |
| 57 | + command = "~/.local/share/nvim/mason/packages/codelldb/extension/adapter/codelldb", |
| 58 | + }, |
| 59 | + host = "127.0.0.1", |
| 60 | + port = "${port}", |
| 61 | + type = "server", |
| 62 | + }, |
| 63 | +} |
| 64 | + |
| 65 | +-- rust config that runs cargo build before opening dap ui and starting Debugger |
| 66 | +-- shows cargo build status as fidget progress |
| 67 | +-- the newly built bootc binary is copied to the VM and run in the lldb-server |
| 68 | +dap.configurations.rust = { |
| 69 | + { |
| 70 | + args = { "status" }, |
| 71 | + cwd = "/", |
| 72 | + name = "[remote] status", |
| 73 | + program = program, |
| 74 | + request = "launch", |
| 75 | + console = "integratedTerminal", |
| 76 | + stopOnEntry = false, |
| 77 | + type = "lldb", |
| 78 | + initCommands = { |
| 79 | + "platform select remote-linux", |
| 80 | + "platform connect connect://bootc-lldb:1234", -- connect to the lldb-server running in the VM |
| 81 | + "file target/debug/bootc", |
| 82 | + }, |
| 83 | + }, |
| 84 | + { |
| 85 | + args = { "upgrade" }, |
| 86 | + cwd = "/", |
| 87 | + name = "[remote] upgrade", |
| 88 | + program = program, |
| 89 | + request = "launch", |
| 90 | + console = "integratedTerminal", |
| 91 | + stopOnEntry = false, |
| 92 | + type = "lldb", |
| 93 | + initCommands = { |
| 94 | + "platform select remote-linux", |
| 95 | + "platform connect connect://bootc-lldb:1234", |
| 96 | + "file target/debug/bootc", |
| 97 | + }, |
| 98 | + }, |
| 99 | + |
| 100 | + -- The install command can connect to a container instead of a VM. |
| 101 | + -- The following command is an example of how to run a container and start a lldb-server: |
| 102 | + -- sudo podman run --pid=host --network=host --privileged --security-opt label=type:unconfined_t -v /var/lib/containers:/var/lib/containers -v /dev:/dev -v .:/output localhost/bootc-lldb lldb-server platform --listen "*:1234" --server |
| 103 | + { |
| 104 | + args = { "install", "to-disk", "--generic-image", "--via-loopback", "--skip-fetch-check", "~/.cache/bootc-dev/disks/test.raw" }, |
| 105 | + cwd = "/", |
| 106 | + env = { |
| 107 | + ["RUST_LOG"] = "debug", |
| 108 | + ["BOOTC_DIRECT_IO"] = "on", |
| 109 | + }, |
| 110 | + name = "[remote] install to-disk", |
| 111 | + program = program, |
| 112 | + request = "launch", |
| 113 | + console = "integratedTerminal", |
| 114 | + stopOnEntry = false, |
| 115 | + type = "lldb", |
| 116 | + initCommands = { |
| 117 | + "platform select remote-linux", |
| 118 | + "platform connect connect://127.0.0.1:1234", -- connect to the lldb-server running in the container |
| 119 | + "file target/debug/bootc", |
| 120 | + }, |
| 121 | + }, |
| 122 | +} |
0 commit comments