多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 环境 * vscode * gcc5.4 * ubuntu16.04 或者 ubuntu18.04 * make 下载[6.2](https://github.com/redis/redis/tree/6.2)版本. 我使用的是国内github镜像地址:github.com.cnpmjs.org,速度比较快。 ```shell $ git clone https://github.com.cnpmjs.org/redis/redis.git redis $ git checkout -b 6.2 remotes/origin/6.2 ``` ## VScode**不参与编译**,只充当**可视化的调试工具**。 使用插件: * C/C++ 先编译redis ``` cd redis && make -j4 ``` 打开redis目录后直接按F5,会出现选择启动调试。选择`c++(GDB/LLDB)` 选择之后在左边的.vscode目录下会出现launch.json文件,将`program`修改为`${workspaceFolder}/src/redis-server` ```json { "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/src/redis-server", "args": ["redis.conf"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] } ``` 这样配置了之后可以按F5直接运行调试啦。 ## VScode**编译调试**redis 使用插件: * C/C++ 在`.vscode`目录下新建 `tasks.json`(“CFLAGS="-g -O0"“参数是为了编译debug版本), ```json { "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "make", "args": [ "CFLAGS=\"-g -O0\"" ] } ] } ``` 修改`launch.json`->`preLaunchTask: Build`使得`tasks.json`可以被加载 ```json { "version": "0.2.0", "configurations": [ { "name": "(gdb) 启动", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/src/redis-server", "args": ["redis.conf"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "preLaunchTask": "build", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] } ``` 这样配置了之后可以按F5直接编译运行调试啦。