39
Debugging a Crash in Unsafe Rust with Windbg
Lately, I had a crash in my Rust project on Windows. It is hard to get any clue from the console messages, because it is a segmentfault crash related to unsafe rust code.
error: process didn't exit successfully: `target\debug\rustdesk.exe` (exit code: 0xc0000374, STATUS_HEAP_CORRUPTION)
I am familiar with Linux debugging tools like GDB and Valgrind. So I attempted to use Windbg.
Download and install Windbg via below link first.
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools
Start your program
cargo run
. It is ok to run release version, but debug version has a bit of nicer symbol information.Open Windbg, and attach your process as below.

Then the process is attached and paused. Please click on "Go" button on Windbg toolbar to continue the process.
This is not the exact location that caused the crash,but it does help me solve the problem.