Is there a way to run the program built by Cargo immediately in gdb
? cargo
has lots of functions and can run the program, so it seems plausible.
The expected command would be something like cargo debug
.
The standard LLDB installation provides you with an extensive set of commands designed to be compatible with familiar GDB commands. In addition to using the standard configuration, you can easily customize LLDB to suit your needs. Both GDB and LLDB are of course excellent debuggers without doubt.
In brief, LLDB and GDB are two debuggers. The main difference between LLDB and GDB is that in LLDB, the programmer can debug programs written in C, Objective C and C++ while, in GDB, the programmer can debug programs written in Ada, C, C++, Objective C, Pascal, FORTRAN and Go.
In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )
No, there's nothing like this currently built into Cargo.
There's a few issues (1, 2) to better support similar issues.
The best thing you could do at the moment would be to write a Cargo subcommand that does exactly what you need.
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
[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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With