{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/src/redis-server",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
- 在
.vscode
目录中新建task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make",
"args": [
"-j4"
]
}
]
}
- 修改launch.json->preLaunchTask: Build使得tasks.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
}
]
}
]
}
Clion调试3.0源码
- 下载黄建宏大神注释的源码
git clone https://github.com/huangz1990/redis-3.0-annotated.git
- 打开redis-3.0-annotated作为Makefile工程
- 编译程序
- 配置启动项 选择redis-server->edit Configurations
- 选择executable,找到redis-server程序
- 在src/redis.c中找到main函数,打个断点
- 点击调试按钮启动调试
Clion调试6.2源码
- 拉取redis源码
git clone -b 6.2 https://github.com/redis/redis.git redis6.2
后续步骤与3.0的一样
技术参考
C/C++Linux服务器开发/后台架构师:https://ke.qq.com/course/417774?flowToken=1041607