首頁>技術>

因為已經熟悉了Java IDEA,Clion是Jetbrian旗下產品,使用習慣應該差不多,mac平臺上vs code之類的不太熟,Xcode又比較反人類。

出於興趣,想閱讀一下Redis的原始碼,如果能在本地除錯,對理解可能有幫助。

於是在Clion下折騰了一番。對C的專案還沒有什麼概念,折騰花了一些時間。如果有對這個比較瞭解的同學看到這個,能帶一帶就太好了

Clion版本:

CLion 2020.3.1Build #CL-203.6682.181, built on December 31, 2020Licensed to xxxSubscription is active until January 15, 2022.For educational use only.Runtime version: 11.0.9.1+11-b1145.63 aarch64VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.macOS 11.2.3GC: ParNew, ConcurrentMarkSweepMemory: 2987MCores: 8Registry: run.processes.with.pty=TRUE

gcc版本:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1Apple clang version 12.0.0 (clang-1200.0.32.29)Target: arm64-apple-darwin20.3.0Thread model: posixInstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

配置構建工具鏈

1、Preferences->Build,Excution,Deployment->Custom Build Targets

Clone redis原始碼 Clion開啟專案

獲取程式碼隨便切到一個穩定版本

git clone git@github.com:redis/redis.gitgit checkout origin/6.0

配置Run/Debug configuation

點選新增按鈕,選擇Custom Build Application,選擇配置好的構建工具,選擇好可執行檔案和配置檔案的路徑

找到server.c

不知道啟動時會載入到哪一行,於是搜尋了一下init(找了crc64_init();打個斷點,之後在選單欄啟動服務

可以斷點除錯了。也能跳轉程式碼,看程式碼就比較方便了。

找常用命令

對這種型別的專案實在不熟,瞎猜了一番也沒猜中,比如搜尋了set,get,scan等命令也沒找到入口在哪裡。於是去翻看了一下readme.md,發現有這麼一段描述

db.c---Certain Redis commands operate on specific data types; others are general.Examples of generic commands are `DEL` and `EXPIRE`. They operate on keysand not on their values specifically. All those generic commands aredefined inside `db.c`.Moreover `db.c` implements an API in order to perform certain operationson the Redis dataset without directly accessing the internal data structures.The most important functions inside `db.c` which are used in many commandimplementations are the following:* `lookupKeyRead()` and `lookupKeyWrite()` are used in order to get a pointer to the value associated to a given key, or `NULL` if the key does not exist.* `dbAdd()` and its higher level counterpart `setKey()` create a new key in a Redis database.* `dbDelete()` removes a key and its associated value.* `emptyDb()` removes an entire single database or all the databases defined.The rest of the file implements the generic commands exposed to the client.

其中dbAdd大機率就是我們常用的set命令了,找到db.c中這個方法,打上斷點,在終端連線到本地redis server,隨便set一個key進來,發現斷點生效

常用的find usage等功能也都正常。

環境搭好了,後面再慢慢研究吧。

參考資料

https://www.jetbrains.com/help/clion/custom-build-targets.html

6
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 業務團隊如何統一架構設計風格?