Redis6 源码调式
Posted 天宇轩-王
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis6 源码调式相关的知识,希望对你有一定的参考价值。
Redis6 源码调式
安装Cygwin
1、下载安装Cygwin
去Cygwin的官方网站http://www.cygwin.com/
window 64位请选择 setup-x86_64.exe 32位请选择 setup-x86.exe下载完成后,运行setup.exe程序,出现安装画面,如下图所示:
上面步骤建议默认下一步。
2、关键步骤
在这一步,需要注意,为了获得最快的下载速度提供三个下载地址
-
首先在列表中寻找Cygwin中国镜像的地址:http://www.cygwin.cn/
这里以163镜像为例,选择完成后,点击“下一步”,
接下来选择安装的软件,Search处分别搜索 gcc-core、gcc-g++、make、gdb、binutils,
选择devel目录下的相关版本,选择Reinstall重新下载。
然后下一步,下一步,就看各位网速了,静等下载成功。
3、验证Cygwin是否安装成功
运行cygwin,在弹出的命令行窗口输入:cygcheck -c cygwin
还要安装一个apt-cyg(相当于是linux下的yum,cygwin下没有yum命令)
安装了apt-cyg就能向使用Ubuntu一样使用apt-get install/remove命令安装卸载软件了,非常方便。GitHub下载脚本:https://github.com/transcode-open/apt-cyg
复制apt-cyg,粘贴到cygwin的安装目录的bin目录下,然后执行命令
然后在系统变量中添加配置
安装clion
CLion 是 JetBrains 推出的全新的 C/C++ 跨平台集成开发环境。习惯了用idea的java程序员用clion来调试redis源码应该比较舒适,比起vc要舒服多了。
Clion中导入redis源码
导入Reids源码之前,需要添加一个CMakeLists.txt
/CMakeLists.txt
./deps/CMakeLists.txt
./deps/linenoise/CMakeLists.txt
./deps/lua/CMakeLists.txt
./src/modules/CMakeLists.txt
/CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(redis VERSION 6.0)
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type defined; defaulting to \'Debug\'")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"The type of build. Possible values are: Debug, Release, RelWithDebInfo and MinSizeRel.")
endif()
message(STATUS "Host is: $CMAKE_HOST_SYSTEM. Build target is: $CMAKE_SYSTEM")
get_filename_component(REDIS_ROOT "$CMAKE_CURRENT_SOURCE_DIR" ABSOLUTE)
message(STATUS "Project root directory is: $REDIS_ROOT")
# Just for debugging when handling a new platform.
if (false)
message("C++ compiler supports these language features:")
foreach(i $CMAKE_CXX_COMPILE_FEATURES)
message(" $i")
endforeach()
endif()
message(STATUS "Generating release.h...")
execute_process(
COMMAND sh -c ./mkreleasehdr.sh
WORKING_DIRECTORY $REDIS_ROOT/src/
)
add_subdirectory(deps)
add_subdirectory(src/modules)
set(SRC_SERVER_TMP
src/crcspeed.c
src/crcspeed.h
src/sha256.c
src/sha256.h
src/connection.c
src/connection.h
src/acl.c
src/timeout.c
src/tracking.c
src/tls.c
src/adlist.c
src/ae.c
src/anet.c
src/dict.c
src/sds.c
src/zmalloc.c
src/lzf_c.c
src/lzf_d.c
src/pqsort.c
src/zipmap.c
src/sha1.c
src/ziplist.c
src/release.c
src/networking.c
src/util.c
src/object.c
src/db.c
src/replication.c
src/rdb.c
src/t_string.c
src/t_list.c
src/t_set.c
src/t_zset.c
src/evict.c
src/defrag.c
src/module.c
src/quicklist.c
src/expire.c
src/childinfo.c
src/redis-check-aof.c
src/redis-check-rdb.c
src/lazyfree.c
src/geohash.c
src/rax.c
src/geohash_helper.c
src/siphash.c
src/geo.c
src/t_hash.c
src/config.c
src/aof.c
src/pubsub.c
src/multi.c
src/debug.c
src/sort.c
src/intset.c
src/syncio.c
src/cluster.c
src/crc16.c
src/endianconv.c
src/slowlog.c
src/scripting.c
src/bio.c
src/rio.c
src/rand.c
src/memtest.c
src/crc64.c
src/bitops.c
src/sentinel.c
src/notify.c
src/setproctitle.c
src/blocked.c
src/hyperloglog.c
src/latency.c
src/sparkline.c
src/t_stream.c
src/lolwut.c
src/lolwut.h
src/lolwut5.c
src/lolwut6.c
src/listpack.c
src/localtime.c
src/gopher.c
)
set(SRC_SERVER src/server.c $SRC_SERVER_TMP)
set(SRC_CLI
src/anet.c src/sds.c src/adlist.c src/redis-cli.c src/zmalloc.c src/release.c src/anet.c src/ae.c src/crc64.c
)
if ($CMAKE_SYSTEM_NAME MATCHES "Linux")
# better not to work with jemalloc
endif()
add_executable(redis-server $SRC_SERVER)
add_executable(redis-cli $SRC_CLI)
set_property(TARGET redis-server PROPERTY C_STANDARD 99)
set_property(TARGET redis-server PROPERTY CXX_STANDARD 11)
set_property(TARGET redis-server PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET redis-cli PROPERTY C_STANDARD 99)
set_property(TARGET redis-cli PROPERTY CXX_STANDARD 11)
set_property(TARGET redis-cli PROPERTY CXX_STANDARD_REQUIRED ON)
target_include_directories(redis-server
PRIVATE $REDIS_ROOT/deps/hiredis
PRIVATE $REDIS_ROOT/deps/linenoise
PRIVATE $REDIS_ROOT/deps/lua/src
)
target_include_directories(redis-cli
PRIVATE $REDIS_ROOT/deps/hiredis
PRIVATE $REDIS_ROOT/deps/linenoise
PRIVATE $REDIS_ROOT/deps/lua/src
)
target_link_libraries(redis-server
PRIVATE pthread
PRIVATE m
PRIVATE lua
PRIVATE linenoise
PRIVATE hiredis
)
target_link_libraries(redis-cli
PRIVATE pthread
PRIVATE m
PRIVATE linenoise
PRIVATE hiredis
)
link_directories(deps/hiredis/ deps/linenoise/ diredeps/lua/src)
./deps/CMakeLists.txt
add_subdirectory(hiredis)
add_subdirectory(linenoise)
add_subdirectory(lua)
./deps/linenoise/CMakeLists.txt
add_library(linenoise linenoise.c)
./deps/lua/CMakeLists.txt
set(LUA_SRC
src/lauxlib.c
src/liolib.c
src/lopcodes.c
src/lstate.c
src/lobject.c
src/print.c
src/lmathlib.c
src/loadlib.c
src/lvm.c
src/lfunc.c
src/lstrlib.c
src/lua.c
src/linit.c
src/lstring.c
src/lundump.c
src/luac.c
src/ltable.c
src/ldump.c
src/loslib.c
src/lgc.c
src/lzio.c
src/ldblib.c
src/strbuf.c
src/lmem.c
src/lcode.c
src/ltablib.c
src/lua_struct.c
src/lapi.c
src/lbaselib.c
src/lua_cmsgpack.c
src/ldebug.c
src/lparser.c
src/lua_cjson.c
src/fpconv.c
src/lua_bit.c
src/llex.c
src/ltm.c
src/ldo.c
)
add_library(lua STATIC $LUA_SRC)
./src/modules/CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
set(CMAKE_BUILD_TYPE "Debug")
add_library(helloworld SHARED helloworld.c)
set_target_properties(helloworld PROPERTIES PREFIX "" SUFFIX ".so")
add_library(hellotype SHARED hellotype.c)
set_target_properties(hellotype PROPERTIES PREFIX "" SUFFIX ".so")
add_library(helloblock SHARED helloblock.c)
set_target_properties(helloblock PROPERTIES PREFIX "" SUFFIX ".so")
add_library(testmodule SHARED testmodule.c)
set_target_properties(testmodule PROPERTIES PREFIX "" SUFFIX ".so")
在编译之前,需要在Cygwin64 Terminal上执行 mkreleasehdr.sh 脚本,由于该脚本格式是win格式,所以需要执行dos2unix命令转换,转换完之后再执行
##转换格式
dos2unix mkreleasehdr.sh
##执行mkreleasehdr.sh
./mkreleasehdr.sh
编译&调试redis6源码
1)、redis6源码加载之后,cmake会自动编译,编译完成后,选择redis-server|debug选项,点击【运行】即可
-
如果想断点的话,要下载一个reids-cli的windows客户端。
断点结果如下:
以上是关于Redis6 源码调式的主要内容,如果未能解决你的问题,请参考以下文章