Redis源码解析 | VScode调试
环境
- vscode- gcc5.4
- ubuntu16.04 或者 ubuntu18.04
- make
下载6.2版本. 我使用的是国内github镜像地址:github.com.cnpmjs.org,速度比较快。
$ 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
{<!-- -->
"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版本),
{<!-- -->
"version": "2.0.0",
"tasks": [
{<!-- -->
"label": "build",
"type": "shell",
"command": "make",
"args": [
"CFLAGS=\"-g -O0\""
]
}
]
}
修改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
}
]
}
]
}
这样配置了之后可以按F5直接编译运行调试啦。
--完--
- 原文作者: 留白
- 原文链接: https://zfunnily.github.io/2021/01/vscodedebugredis/
- 更新时间:2024-04-16 01:01:05
- 本文声明:转载请标记原文作者及链接