1、vscode安裝插件 C/C++ (ms-vscode.cpptools),安裝后運行Run->Start Debugging會出現C++(GDB/LLDB)與C++(Windows)
2、根據rust用的版本,如果用的是x86_64-pc-windows-msvc,調試時選擇C++(Windows), 如果是x86_64-pc-windows-gnu,調試時選擇C++(GDB/LLDB)。
選擇C++(Windows)時, 會出現如下配置信息(launch.json),自己修改program,設置要調試的程序。(安裝visual studio)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) 啟動",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/rust/rust-test/r019echo-async/target/debug/r019echo-async.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false
}
]
}
選擇C++(GDB/LLDB)時,會出現下面的信息,自己設置要調試的程序與gdb所在的路徑。(安裝 mingw64)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 啟動",
"type": "cppdbg",
"request": "launch",
"program": "輸入程序名稱,例如 ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "為 gdb 啟用整齊打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
3、調試過程中,當要跟蹤到rust內部代碼時,會跳出如下提示框,這時需要建一個C:\rustc\b8cedc00407a4c56a3bda1ed605c6fc166655447的目錄,並將用戶目錄下的.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src拷到前面的目錄下。這樣就能跟蹤到內部代碼了。
4、設置斷點有問題,可以安裝一下Native Debug插件。