Debugging Rust

Rust compiles into machine code the same as C and benefits from sharing the same ABI and compiler backend formats as C/C++.

So you can debug Rust in the same way as C/C++. If you built your Rust executable in a gcc compatible binary format you can just invoke gdb on it:

gdb my_executable

Rust comes with a gdb wrapper script called rust-gdb that loads macros which perform syntax highlighting.

Enabling backtrace

If your code is crashing because of a panic!() you can get a backtrace on the console by setting the RUST_BACKTRACE environment variable.

# Windows
# Unix/Linux

Find out your target binary format

If you are in doubt what you are targeting, you may use rustup to show you.

c:\dev\visu>rustup show
Default host: x86_64-pc-windows-msvc

stable-x86_64-pc-windows-msvc (default)
rustc 1.13.0 (2c6933acc 2016-11-07)

Or perhaps:

[foo@localhost ~]$ rustup show
Default host: x86_64-unknown-linux-gnu

stable-x86_64-unknown-linux-gnu (default)
rustc 1.13.0 (2c6933acc 2016-11-07)

The information will tell you which debugger you can use to debug your code.

Microsoft Visual Studio

If you have the MSVC toolchain (32 or 64-bit) or the LLVM backend will generate a .pdb file and binaries will be compatible with the standard MSVC runtime.

To debug your code:

  1. Open Visual Studio
  2. Choose File | Open | Project/Solution...
  3. Select the compiled executable
  4. Open a source file to debug and set a breakpoint
  5. Click the "Start" button


GDB can be invoked directly from the command line or through a plugin / IDE. From the command line it's a




results matching ""

    No results matching ""