Skip to content

Commit

Permalink
Merge pull request #211 from beeender/mc/cargo
Browse files Browse the repository at this point in the history
Support cargo-debug
  • Loading branch information
sakhnik authored Oct 29, 2024
2 parents 952f0b4 + 9478b6d commit a8a5289
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
4 changes: 4 additions & 0 deletions doc/nvimgdb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
23 changes: 17 additions & 6 deletions lua/nvimgdb/backend/gdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
21 changes: 18 additions & 3 deletions lua/nvimgdb/backend/lldb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit a8a5289

Please sign in to comment.