# 启动后执行 "run" 开始运行Redis (gdb) r Starting program: /usr/local/bin/redis-server [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 4461:C 03 Sep 2025 23:26:40.692 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 4461:C 03 Sep 2025 23:26:40.692 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=4461, just started 4461:C 03 Sep 2025 23:26:40.692 # Warning: no config file specified, using the default config. In order to specify a config file use /usr/local/bin/redis-server /path/to/redis.conf 4461:M 03 Sep 2025 23:26:40.694 * Increased maximum number of open files to 10032 (it was originally set to 1024). 4461:M 03 Sep 2025 23:26:40.694 * monotonic clock:POSIX clock_gettime _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running instandalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 4461 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
4461:M 03 Sep 2025 23:26:40.699 # Server initialized 4461:M 03 Sep 2025 23:26:40.699 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and thenreboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. [New Thread 0x7ffff69ff640 (LWP 4464)] [New Thread 0x7ffff61fe640 (LWP 4465)] [New Thread 0x7ffff59fd640 (LWP 4466)] [New Thread 0x7ffff51fc640 (LWP 4467)] 4461:M 03 Sep 2025 23:26:40.704 * Ready to accept connections
三、gdb 核心调试技巧(Redis 场景化应用)
以下命令结合 Redis 源码逻辑设计,覆盖命令处理、键操作、线程行为等核心场景。
1. 断点设置(精准定位核心流程)
Redis 的核心函数是调试重点,需掌握「普通断点」「条件断点」「函数断点」的用法。
调试场景
gdb 命令示例
说明
拦截所有命令处理
break processCommand
processCommand是所有客户端命令的入口函数(如 GET/SET),断点后可跟踪命令流程
拦截特定命令(如 SET)
break processCommand if strcasecmp(cmd->name, "SET") == 0