需求
使用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