【发布时间】:2020-09-27 03:08:58
【问题描述】:
我可以在不添加文件的情况下进行调试,但是,我不知道如何处理添加文件。
命令如下:
g++ -g --std=c++11 lab1.cpp -o lab1
./lab1 ./tests/extracredit-test-0.txt
以下是我的task.json 和launch.json。我想知道如何修改它以支持添加文件的调试。
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": [
{
"preLaunchTask": "build active file",
"name": "CodeLLDB",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
},
{
"preLaunchTask": "build active file",
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
},
{
"name": "GDB",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"cwd": "${workspaceFolder}",
"MIMode": "gdb"
}
]
}
task.json
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
"version": "2.0.0",
"tasks": [
{
"label": "build active file",
"type": "shell",
"command": "g++ --std=c++11 ${file} -g -o ${fileDirname}/${fileBasenameNoExtension}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"osx": {
"command": "g++ --std=c++11 ${file} -g -o ${fileDirname}/${fileBasenameNoExtension}",
},
"windows": {
"command": "g++",
"args": [
"-ggdb",
"\"${file}\"",
"--std=c++11",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}\""
]
}
}
]
}
【问题讨论】:
标签: c++ debugging gcc visual-studio-code