How to use clion to debug redis source code on mac system
clion mainly uses cmake
+ make
for compilation. So for redis4, the main thing is to write the CMakeLists.txt file first.
CmakeLists.txt file
redis4/CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(redis4)
set(CMAKE_BUILD_TYPE "Debug")
get_filename_component(REDIS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
add_subdirectory(deps)
add_subdirectory(src/modules)
set(SRC_SERVER_TMP
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
)
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
)
set(EXECUTABLE_OUTPUT_PATH src)
link_directories(deps/linenoise/ deps/lua/src deps/hiredis)
add_executable(redis-server ${SRC_SERVER})
target_include_directories(redis-server
PRIVATE ${REDIS_ROOT}/deps/linenoise
PRIVATE ${REDIS_ROOT}/deps/hiredis
PRIVATE ${REDIS_ROOT}/deps/lua/src)
target_link_libraries(redis-server
PRIVATE pthread
PRIVATE m
PRIVATE lua
PRIVATE linenoise
PRIVATE hiredis)
add_executable(redis-cli ${SRC_CLI})
target_include_directories(redis-cli
PRIVATE ${REDIS_ROOT}/deps/linenoise
PRIVATE ${REDIS_ROOT}/deps/hiredis
PRIVATE ${REDIS_ROOT}/deps/lua/src)
target_link_libraries(redis-cli
PRIVATE pthread
PRIVATE m
PRIVATE linenoise
PRIVATE hiredis)
redis4/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")
redis4/deps/CMakeLists.txt
add_subdirectory(linenoise)
add_subdirectory(lua)
add_subdirectory(hiredis)
redis4/deps/lua/CMakeLists.txt
add_subdirectory(src)
redis4/deps/lua/src/CMakeLists.txt
set(LUA_SRC
lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c
lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c
lundump.c lvm.c lzio.c strbuf.c fpconv.c
lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c ltablib.c
lstrlib.c loadlib.c linit.c lua_cjson.c lua_struct.c lua_cmsgpack.c
lua_bit.c
)
add_library(lua STATIC
${LUA_SRC}
)
redis4/deps/linenoise/CMakeLists.txt
add_library(linenoise
linenoise.c
)
redis4/deps/hiredis/CMakeLists.txt
add_library(hiredis STATIC
hiredis.c
net.c
dict.c
net.c
sds.c
async.c
read.c
)
All CMakeLists.txt
the files have been written. Next, create a new redis4 project in CLion
Create a new redis4 project in CLion
Select File->New Cmake Project from Source... and select our redis4
folder.
Note: Do not overwrite what is written above
CMakeLists.txt
, so selectOpening Existing Project
ok instead of okImport as a new Cmake Project
.
After creating a new project, CLion will automatically cmake
build the project. After the build is complete, you will find the following run items.
Select redis-server
and then select the run/debug button on the right
The following result indicates success.
In this way, we can breakpoint and debug. If all the above configurations are successful, they can be run directly. However, reality is always cruel, and various problems often occur, which need to be solved according to the actual problems. For example, if we are currently using a Mac system, if we switch to a Linux system for remote debugging, will it still be so smooth? These need to be solved according to the actual situation when we actually encounter them.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Creating a signature from Hash_hmac() and Sha256 in PHP
Publish Date:2025/04/13 Views:107 Category:PHP
-
PHP has one of the best encryption functions for data security. Hash_hmac() The encrypt function is one of the most famous encryptors. We'll show you how to use hash_hmac and sha256 encryptors to create 安全签名 one that you can store i
Running PHP on Mac
Publish Date:2025/04/12 Views:183 Category:PHP
-
In this article, we'll show you how to run PHP on your Mac. php -S Run PHP on Mac using command PHP is a server-side language. It runs on a server. Therefore, it requires a web server to run. There are different web servers like Apache HTTP
Redis password verification command AUTH
Publish Date:2025/04/09 Views:78 Category:Redis
-
Redis has not made much optimization in terms of security, but has made great efforts in terms of performance and ease of use. A very simple security method for Redis is password verification, which requires the use of the AUTH command. Let
Redis installation method and common problem solving under centos
Publish Date:2025/04/09 Views:158 Category:Redis
-
In this article, we will introduce how to install redis under CentOS. In fact, the installation steps are very simple, but there may be some problems in the middle, which is worthy of our attention. Let's take a look at how to install it. F
Mac system uses clion to remotely debug redis4 source code
Publish Date:2025/04/09 Views:129 Category:Redis
-
The remote host uses the Linux system. The first step is definitely to establish a code synchronization mechanism on the local and remote hosts - sftp is the first choice. The second step is to write the CMakeLists.txt file of redis4. There
Solve the problem of gdb debugging on Mac system
Publish Date:2025/04/07 Views:93 Category:OPERATING SYSTEM
-
On a Mac, you may encounter the following error when using gdb for the first time: (gdb) run Starting program: /usr/ local /bin/order_monitor Unable to find Mach task port for process-id 26551: (os/kern) failure (0x5). (please check gdb is
Mac Modify the host name and prompt in terminal and iterm
Publish Date:2025/04/07 Views:178 Category:OPERATING SYSTEM
-
Commonly used terminals on Mac are terminal and iterm. In many cases, we need to modify the host name displayed in these terminals. As shown in the figure above, we use the command hostname to view the current host name From the results we
PHPStorm shortcut keys for Win/Linux/Mac
Publish Date:2025/04/07 Views:125 Category:OPERATING SYSTEM
-
edit Win / Linux Mac Notes Frequency of use Ctrl + Space ⌃Space Code auto-completion (usually conflicts with input method) ★☆☆☆☆ Ctrl + Shift + Enter ⌘ ⇧ ↩ Intelligent code completion (such as: if ()) ★☆☆☆☆ Ctrl
Mac shuts down BaiduNetdiskSync service
Publish Date:2025/04/07 Views:193 Category:OPERATING SYSTEM
-
I don't know if you have installed Baidu Netdisk on your Mac. If you have installed and used it, we will find through Activity Monitor that there is a baiduNetdiskSync service that has always existed. It is very distressing. Let's shut down