Problems with debugging programs and GDB

Hi, I have some troubles using gdb with rust. What I do:

cargo new hello_world --bin
cd hello_world
cargo build
[rust-]gdb target/debug/hello_world

If i then enter start and open source layout with C-x a, then all I see is "no source available". Single-stepping through the program with next doesn't seem to work for me either.

I see this on both Arch (gdb 7.12) and Fedora 24 (gdb 7.11.1). I suppose this is not expected behavior. What am I missing? What am I doing wrong? Do I have something misconfigured?

Thanks for your help

If I remember correctly, you have not only to provide the binary, but also the source code.

Ok, I finally figured out what the problem was: I need to set the breakpoint with break hello_world::main.

Before I got this output for next:

Single stepping until exit from function main,
which has no line number information.

What's happening here is that rust provides its own main that then calls your hello_world::main. However, the provided main doesn't have debugging information in your case. This prevents next from working in gdb.

You found a good workaround. I also sometimes just put a breakpoint where I'm interested in debugging before run (and avoiding start).

Long term my preferred fix is described in emit DW_AT_main_subprogram · Issue #32620 · rust-lang/rust · GitHub.