How to Use GDB with Rust Programs

Compile Rust with debug symbols and attach GDB to the binary in target/debug to inspect variables and step through code.

Compile your Rust program with debug symbols using cargo build and attach GDB to the resulting binary in the target/debug directory.

cargo build
gdb ./target/debug/your_binary_name

Inside GDB, set a breakpoint on your main function and run the program:

(gdb) break main
(gdb) run

If you need custom pretty-printers for Rust types, use the gdb_script_file attribute in your code and source the script in GDB:

#[debugger_visualizer(gdb_script_file = "path/to/your_script.py")]

Then in GDB:

(gdb) source path/to/your_script.py