Debugging Rust on Windows?



I am a super newbie to rust and trying to learn rust with lots of enthusiasm.

I am using Visual studio code with RustyCode extension and GDB to debug. But I don’t get it working correctly.

Some help would be much appreciated. Snapshot of what the error look like below


I’d suspect that VS code doesn’t deal correctly with cygwin paths. Did you try to start it from a non-cygwin shell?


My guess is that you are trying to use cygwin’s gdb for debugging. This probably won’t work, you will need a gdb for proper Windows. I haven’t tried to use gdb with such setup so can’t help you here.

As an alternative it is possible to use Visual Studio (not Code) to debug Rust programs but last time I tried it it only supported stepping thru code (step by step or stopping at breakpoints) but it wasn’t able to display content of any variable. You will need to compile your program to *-pc-windows-msvc target instead of *-pc-windows-gnu. Then you can debug it in VS as described here or here. But as I said it is not very useful.


Thanks for the insight.

I have switched to . Which I came to know from here

But now there is some weird behavior.

I created a small video of what I am trying to say.


What is your debug configuration in VS Code? (launch.json file)


“version”: “0.2.0”,
“configurations”: [
“name”: “Debug”,
“type”: “gdb”,
“request”: “launch”,
“target”: “target/debug/vscodetest”,
“cwd”: “${workspaceRoot}”


Not 100% sure, but here are my guesses:

  • The Python error is because Rust binaries contain a gdb auto-load section for pretty printer scripts, which rely on a custom module shipped with Rust. If you run rust-gdb script (from Rust distro’s /etc folder) instead of plain gdb, it will set up module search paths correctly, and this should work.
  • The stepping-over-a-macro problem should be already fixed in the nightly channel.
  • The variables are allocated stack space in prologue of the function, but aren’t initialized until you step past their declarations/assignments. (Yes, ideally they wouldn’t be in scope until declaration. I think rustc actually tries to do the right thing here, not sure why it isn’t working).
  • I am guessing that the closing function brace corresponds to a point in code after the epilogue, so the variables don’t exist anymore. We should probably adjust this.


What do you mean by "If you run rust-gdb script (from Rust distro’s /etc folder) "? Can you explain?

With Linux Rust archive in rustc/lib/rustlib/etc there are


And in How to set up GDB for debugging Rust programs in Windows? , to enable pretty-printers, It’s indicated

import gdb_rust_pretty_printing


There is also a file rust-gdb which I suppose a shell script and can be run using that. I did it in windows using git-bash. But as of now I did not understand what it suppose to do :slight_smile:

It gave me error like this:

nisu@NWISU02 MINGW64 /c/Users/nisu/.cargo/rustc-1.11.0/src/etc
$ sh rust-gdb
GNU gdb (GDB) 7.9.1
Copyright © 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and “show warranty” for details.
This GDB was configured as “x86_64-w64-mingw32”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type “help”.
Type “apropos word” to search for commands related to “word”.
---- Loading Rust pretty-printers ----
Traceback (most recent call last):
File “”, line 4, in
ImportError: No module named gdb_rust_pretty_printing
c:\rustdebug\gdb64\bin…/bin/gdbinit:18: Error in sourced command file:
Error while executing Python code.
Warning: C:\Program Files\Rust stable GNU 1.11/lib/rustlib/etc: No such file or directory.


Thanks I will try with the nightly build.


No error, just this warning

---- Loading Rust pretty-printers ----
Warning: D:\Applications\Rust stable GNU 1.11/lib/rustlib/etc: No such file or directory.
(gdb) quit

with Rust 1.11 GNU and this in gdbinit file

print "---- Loading Rust pretty-printers ----"
sys.path.insert(0, "D:/Applications/Rust stable GNU 1.11/bin/rustlib/etc")
import gdb_rust_pretty_printing

But how to call rust-gdb in VS Code?


I can confirm the macro debugging works now. Thanks for the help. I also fixed the pretty print by giving the path of the etc folder correctly.

Once again thanks for the help. A blog post will follow soon How to get it working with Visual Studio Code on Windows :slight_smile:


Hmm I did not try that. I used a usual gdb and that worked.


I’m interesting by your blog post. Post your Url here :wink:


Here it is let me know if things work or do not work :slight_smile:


That probably won’t work. In a similar way to Eclipse/RustDT, the IDE will usually need to start the gdb executable directly. It probably doesn’t support starting a bash script (in part because it needs to control the stdin/stdout of the GDB process). So if you want to enable pretty printers you need to set them up in a way like described here:

And yes, use TDM-GCC’s GDB, not Cygwin’s GDB.


Yo, I noticed you have step “10. Install Python”. I don’t think this is necessary. The TDM-GDB download that was mentioned here already includes Python support. See: , it says 12.3 MB · gdb 7.9.1 GNU debugger — includes Python support..
I got my pretty printers to work without having to install Python separately.


hey thanks. Ill update the blog post.


Do you test with the Release 7.12 of GDB? (Debugging programs written in Rust is now supported with GDB 7.12).


Hmm I do not know how to compile that source. I am not getting any exe of that. If you know please let me know then I can try it out