系统环境:
ubuntu20.04
Visual Studio Code Version 1.60.2
lauch.json配置如下:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}]
}]
}
settings.json配置如下:
{
"files.associations": {
"array": "c",
"atomic": "c",
"*.tcc": "c",
"cctype": "c",
"chrono": "c",
"clocale": "c",
"cmath": "c",
"condition_variable": "c",
"cstdarg": "c",
"cstdint": "c",
"cstdio": "c",
"cstdlib": "c",
"cstring": "c",
"ctime": "c",
"cwchar": "c",
"cwctype": "c",
"deque": "c",
"unordered_map": "c",
"unordered_set": "c",
"vector": "c",
"exception": "c",
"fstream": "c",
"functional": "c",
"initializer_list": "c",
"iomanip": "c",
"iosfwd": "c",
"iostream": "c",
"istream": "c",
"limits": "c",
"mutex": "c",
"new": "c",
"ostream": "c",
"numeric": "c",
"ratio": "c",
"sstream": "c",
"stdexcept": "c",
"streambuf": "c",
"system_error": "c",
"thread": "c",
"cinttypes": "c",
"tuple": "c",
"type_traits": "c",
"utility": "c",
"typeinfo": "c",
"cstddef": "c",
"algorithm": "c",
"iterator": "c",
"map": "c",
"memory": "c",
"memory_resource": "c",
"optional": "c",
"random": "c",
"string": "c",
"string_view": "c",
"bit": "c",
"stdlib.h": "c",
"pehfeatureprecess.h": "c",
"stat.h": "c",
"types.h": "c",
"stdint.h": "c"
}
}
tasks.json配置如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command":"gcc",
"args": ["${file}", "-o", "${fileBasenameNoExtension}.out", "-g"]
}
]
}
原因是task.json配置中我少加了一个“-g”,把-g去掉就不能调试了,程序直接运行完了,打断点也没用。