DEV Community

RustDesk
RustDesk

Posted on

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)
Enter fullscreen mode Exit fullscreen mode

I am familiar with Linux debugging tools like GDB and Valgrind. So I attempted to use Windbg.

Install Windbg

Download and install Windbg via below link first.
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools

Debug with Windbg

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.

image

Then the process is attached and paused. Please click on "Go" button on Windbg toolbar to continue the process.

Now you can run your program until it crashes, and get a crash stack in Windbg as below.
image

This is not the exact location that caused the crash,but it does help me solve the problem.

Top comments (1)

Collapse
 
opedroso profile image
Osiris Pedroso

Next time, consider using runst-windbg for easy of use.
It does all the hard working of getting the environment setup right (for the duration of the script run) such that you can concentrate on debugging your issue.