Use cargo run -- --nocapture to run your program in a debugger, then set breakpoints and watch expressions in your IDE or GDB/LLDB.
cargo run -- --nocapture
In GDB:
(gdb) break main
(gdb) run
(gdb) watch my_variable
(gdb) continue
In VS Code (launch.json):
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"cargo": {
"args": ["run", "--", "--nocapture"]
},
"cwd": "${workspaceFolder}"
}
Set breakpoints by clicking the gutter in your editor. Add watch expressions in the debugger's watch panel (e.g., my_variable, vec.len()).