We are using redis in our stack for many purposes,
I like redis for its no external dependency, light weight, thread safety and out-of-the-box supporting many things like pubsub, streams, secondary indexes (map, set, list) all with efficient data structure selection and ability to extend redis for our own custom data structures if needed.
I've always wondered about its working, though there are many resources available online explaining redis internals, I'm not super confident to say I know this. So decided to read the source of it.
I've struggled to setup C debugging environment on my MacOS without gdb support. Turned out it was simple to setup, But I can't able to find a Blog step-by-step, so here it is.
Tools :
- VSCode
- lldb (gdb alternative), either you can install xcode from app store or just install xcode cli tools by ("xcode-select --install"),
"lldb --version"
to verify if ldb installed.
Get Redis Code base:
git clone https://github.com/redis/redis.git
cd redis
--------------------------------------------------------
open src/Makefile
_ We have to modify Makefile
_ Change the following lines for debugging_
# OPTIMIZATION?=-O2
OPTIMIZATION?=-O0
# REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS) $(OPTIMIZATION)
--------------------------------------------------------
make distclean (clean any intermittent files if any).
make -j 8 (use multi core if possible).
Now lets configure VS Code
Inside redis folder "code ."
or simply open redis folder in vscode.
Install C/C++ extension If you don't have it.
In explorer, under ".vscode" folder add launch.json and add the following configuration.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch (lldb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/src/redis-server",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
Then add a debugger point on "aeMain" function from ae.c file, and continue your debugging journey from there.
Thank you.
References:
VS code official Doc
Redis debugging modifications
Top comments (0)