简体   繁体   English

有没有办法在gdb或lldb中直接运行由Cargo构建的程序?

[英]Is there a way to directly run the program built by Cargo in gdb or lldb?

Is there a way to run the program built by Cargo immediately in gdb ? 有没有办法在gdb立即运行由Cargo构建的程序? cargo has lots of functions and can run the program, so it seems plausible. cargo有很多功能,可以运行程序,所以看起来似乎有道理。

The expected command would be something like cargo debug . 预期的命令就像cargo debug

No, there's nothing like this currently built into Cargo. 不,目前Cargo内置了这样的东西。

There's a few issues ( 1 , 2 ) to better support similar issues. 有几个问题( 12 ),以更好地支持类似的问题。

The best thing you could do at the moment would be to write a Cargo subcommand that does exactly what you need. 你现在可以做的最好的事情就是编写一个完全符合你需要的Cargo子命令

A workaround 解决方法

Without creating a subcommand, you can glue together a few features to get something close. 在不创建子命令的情况下,您可以将一些功能粘合在一起以获得接近的功能。

Start by configuring a custom runner for your architecture. 首先为您的体系结构配置自定义运行器

.cargo/config .cargo /配置

[target.x86_64-apple-darwin]
runner = ["/tmp/gg/debugger.sh"]

Then write a little script to be the test runner. 然后写一个小脚本作为测试运行器。 If an environment variable is set, it will start the debugger, otherwise it will just run the program: 如果设置了环境变量,它将启动调试器,否则它将只运行程序:

#!/bin/bash

if [[ -z $DEBUG ]]; then
    exec $*
else
    exec lldb $*
fi

Then you just need to set the variable: 然后你只需要设置变量:

$ 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)

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM