在 Debian 上配置 Rust 调试环境的完整步骤
一 安装工具链与调试器
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shsource $HOME/.cargo/env,将 ~/.cargo/bin 加入 PATHsudo apt update && sudo apt install gdb(或 sudo apt install lldb)rustup component add rust-src llvm-tools-preview二 构建与符号配置
debug = true三 命令行调试流程
rust-gdb target/debug/your_programbreak main、run、next、step、print x、backtracerust-lldb target/debug/your_programb main、run、n、s、frame variable、btRUST_BACKTRACE=1 cargo run(或 RUST_BACKTRACE=1 target/debug/your_program)四 VS Code 调试配置
{
"version": "0.2.0",
"configurations": [
{
"type": "cppdbg",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "cargo build"
}
]
}
cargo build --release{
"version": "2.0.0",
"tasks": [
{
"label": "cargo build",
"type": "shell",
"command": "cargo build",
"group": { "kind": "build", "isDefault": true },
"problemMatcher": ["$rustc"]
}
]
}
五 内存与性能辅助工具
sudo apt install valgrindvalgrind --tool=memcheck target/debug/your_program