I'm trying to step through this:
fn main() {
println!("Hello {}", 0);
}
I've tried compiling with both: cargo build
and rustc -g -L src/main.rs
I then run gdb target/debug/rust-gdb-test
(or gdb main
), and try to set a breakpoint on main
with break main
.
(break ::rust-gdb-test::main
returns Function "::rust-gdb-test" not defined.
).
After breaking (Breakpoint 1, 0x0000555555559610 in main ()
) if I try to run list
, I get:
1 dl-debug.c: No such file or directory.
I am running Rust 1.10.0 (cfcb716cf 2016-07-03)
and GDB 7.7.1 (Debian 7.7.1+dfsg-5)
.
A similar question was asked 2 years ago, but I couldn't make the solutions presented there to work.
Note: I seem to not have GDB installed anymore, only LLDB, but for this question the answer is the same.
The
main
that you see in Rust is not the samemain
that exists in the compiled binary. Specifically, there are a number of shim methods between the two. The Rustmain
actually includes the crate name (in my examplebuggin
) and a hash (in my casehfe08615ed561bb88
):Here, you can see that
main
is a few frames away in the stack.I tend to use a wildcard breakpoint to not deal with the hash:
rbreak
should be an equivalent in GDB.Once the program is stopped, you should be able to see the source. You may also be interested in the
rust-lldb
andrust-gdb
wrappers that ship with Rust and improve the experience a bit.This is basically the same as this answer, but mentions the hash.
The hyphen (
-
) is not a valid symbol character. When compiled, it is converted to an underscore.My original methodology was actually this:
You can then run the program and continue a few times until you find the right place. Don't be afraid to get in there and explore a bit; it's just a debugger!
You could try various versions of the regex to see if anything interesting might match:
You could also call a function with a very unique name from
main
and set a breakpoint on that: