需求
使用VScode自帶debug工具調試c++代碼,希望傳入指定參數與環境變量。
實現
在./vscode/launch.json
中進行配置
{
// 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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/home/.../target/bin/our_app",
"args": ["-d","1","-v","-o"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [
{ "name": "APP_ROOT", "value": "/home/.../target" },
{ "name": "LD_LIBRARY_PATH", "value": "/home/.../target/3rdparty/lib:"}
],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
參考
Configure launch.json for C/C++ debugging in Visual Studio Code