diff --git a/doc/nvimgdb.txt b/doc/nvimgdb.txt index ff414f0..cde8695 100644 --- a/doc/nvimgdb.txt +++ b/doc/nvimgdb.txt @@ -400,6 +400,10 @@ Section 7.1 GDB, LLDB *NvimgdbGDB* *NvimgdbLLDB* is injected into GDB/LLDB. It spawns a thread listening for commands via a UDP socket, executes them and sends a JSON response back. +- To debug with cargo-debug (https://github.com/cargo-bins/cargo-debug), use + `Gdbstart cargo debug` for gdb backend, or `GdbStartLLDB cargo debug` for + the lldb backend. + ------------------------------------------------------------------------------ Section 7.2 rr *NvimgdbRR* diff --git a/lua/nvimgdb/backend/gdb.lua b/lua/nvimgdb/backend/gdb.lua index ec1f3e8..628a953 100644 --- a/lua/nvimgdb/backend/gdb.lua +++ b/lua/nvimgdb/backend/gdb.lua @@ -104,10 +104,20 @@ function C.get_launch_cmd(client_cmd, tmp_dir, proxy_addr) -- We'd like to ensure gdb is launched with our custom initialization -- injected. - -- Check for rr-replay.py - local gdb = client_cmd[1] - if gdb == "rr-replay.py" then - gdb = utils.get_plugin_file_path("lib", "rr-replay.py") + local cmd_arg = "-ix" + local rest_arg_idx = 2 + local cmd = {client_cmd[1]} + if cmd[1] == "rr-replay.py" then + -- Check for rr-replay.py + cmd = {utils.get_plugin_file_path("lib", "rr-replay.py")} + elseif cmd[1] == "cargo-debug" then + -- Check for cargo + cmd_arg = "--command-file" + elseif cmd[1] == "cargo" then + -- the 2nd arg is the cargo's subcommand, should be 'debug' here + cmd = {'cargo', client_cmd[2]} + cmd_arg = "--command-file" + rest_arg_idx = 3 end local gdb_init = utils.path_join(tmp_dir, "gdb_init") @@ -127,9 +137,10 @@ set pagination off file:close() end - local cmd = {gdb, '-ix', gdb_init} + table.insert(cmd, cmd_arg) + table.insert(cmd, gdb_init) -- Append the rest of arguments - for i = 2, #client_cmd do + for i = rest_arg_idx, #client_cmd do cmd[#cmd + 1] = client_cmd[i] end return cmd diff --git a/lua/nvimgdb/backend/lldb.lua b/lua/nvimgdb/backend/lldb.lua index f3f8102..17dd761 100644 --- a/lua/nvimgdb/backend/lldb.lua +++ b/lua/nvimgdb/backend/lldb.lua @@ -109,7 +109,18 @@ function C.get_launch_cmd(client_cmd, tmp_dir, proxy_addr) -- We'd like to ensure gdb is launched with our custom initialization -- injected. - local lldb = client_cmd[1] + local cmd_args = {'--source-quietly', '-S'} + local rest_arg_idx = 2 + local cmd = {client_cmd[1]} + if cmd[1] == "cargo-debug" then + -- Check for cargo + cmd_args = {'--debugger', 'lldb', '--command-file'} + elseif cmd[1] == "cargo" then + -- the 2nd arg is the cargo's subcommand, should be 'debug' here + cmd = {'cargo', client_cmd[2]} + cmd_args = {'--debugger', 'lldb', '--command-file'} + rest_arg_idx = 3 + end local lldb_init = utils.path_join(tmp_dir, "lldb_init") local file = io.open(lldb_init, "w") @@ -129,9 +140,13 @@ function C.get_launch_cmd(client_cmd, tmp_dir, proxy_addr) end -- Execute lldb finally with our custom initialization script - local cmd = {lldb, '--source-quietly', '-S', lldb_init} + for _, arg in ipairs(cmd_args) do + table.insert(cmd, arg) + end + table.insert(cmd, lldb_init) + -- Append the rest of arguments - for i = 2, #client_cmd do + for i = rest_arg_idx, #client_cmd do cmd[#cmd + 1] = client_cmd[i] end return cmd