有没有办法在gdb
中立即运行Cargo构建的程序? cargo
有很多功能,可以运行程序,所以看起来似乎有道理。
预期的命令类似于 cargo debug
。
最佳答案
不,目前 Cargo 中没有这样的东西。
你现在能做的最好的事情就是写一个 Cargo subcommand这正是您所需要的。
解决方法
无需创建子命令,您可以将一些功能粘合在一起以获得接近的效果。
从配置a custom runner开始为您的架构。
.cargo/config
[target.x86_64-apple-darwin]
runner = ["/tmp/gg/debugger.sh"]
然后编写一个小脚本作为测试运行器。如果设置了环境变量,它将启动调试器,否则它只会运行程序:
#!/bin/bash
if [[ -z $DEBUG ]]; then
exec $*
else
exec lldb $*
fi
然后你只需要设置变量:
$ cargo test
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running target/debug/deps/gg-e5d6c92730ca3c30
running 0 tests
$ DEBUG=1 cargo test
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running target/debug/deps/gg-e5d6c92730ca3c30
(lldb) target create "/private/tmp/gg/target/debug/deps/gg-e5d6c92730ca3c30"
Current executable set to '/private/tmp/gg/target/debug/deps/gg-e5d6c92730ca3c30' (x86_64).
(lldb)
另见:
关于debugging - 有没有办法在gdb或lldb中直接运行Cargo构建的程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52685869/