使用 VSCode 调试 C 代码
一点无聊的 config snippet
Prereq
安装官方 C/C++ plugin,以及编译器工具链(废话
Build config
command-shift-P -> Tasks: Configure Task -> Other
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build C program",
"type": "shell",
"linux":{
"command": "gcc"
},
"osx":{
"command": "clang"
},
"args": [
"-g",
"-o ${fileDirname}/${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Debug config
debug panel -> configure
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"osx": {
"MIMode": "lldb"
},
"linux": {
"MIMode": "gdb"
},
"preLaunchTask": "build C program"
}
]
}
Auto-formatting (非常重要
默认的 Visual Studio 样式有一个非常非常变态的样式:大括号换行。

这样的代码我估计没人受得了。
首选项 -> 设置,加一行 "C_Cpp.clang_format_fallbackStyle": "Google"
,回去再 option-shift-F 格式化一下:

舒服多了。