问下前辈们尝试二开 Redis 报错怎么排查啊

2022-05-27 11:35:51 +08:00
 lbllol365

我这业余时间想试试开源项目,拉了 Redis 源码,就仿照 get 实现了一个新命令,make 和 make test 都过了。redis-server 启动正常,redis-cli 连接正常,然后敲上我的命令,就报错了,redis-server 直接挂了, 核心代码就是这块

dictEntry *dictGetFirst(dict *ht) {
    dictEntry *entry;
    if(dictSize(ht) == 0) {
        return NULL;
    }
    for(int table = 0;table <= 1;table++) {
        entry = ht->ht_table[table][0];
        if(entry) {
            return entry;
        }
    }
    return NULL;
}

下面是提示:

------ STACK TRACE ------
EIP:
./redis-server *:6379(dictGetFirst+0x1a)[0x55ee1d2efbfa]

Backtrace:
/usr/lib/libc.so.6(+0x3e8e0)[0x7f56767de8e0]
./redis-server *:6379(dictGetFirst+0x1a)[0x55ee1d2efbfa]
./redis-server *:6379(getFirst+0x11)[0x55ee1d31d711]
./redis-server *:6379(getFirstCommand+0xf)[0x55ee1d3315df]
./redis-server *:6379(call+0xde)[0x55ee1d2f58ee]
./redis-server *:6379(processCommand+0x92d)[0x55ee1d2f88cd]
./redis-server *:6379(processInputBuffer+0xec)[0x55ee1d31024c]
./redis-server *:6379(readQueryFromClient+0x2e8)[0x55ee1d313a98]
./redis-server *:6379(+0x1444d4)[0x55ee1d3c24d4]
./redis-server *:6379(+0x6eba8)[0x55ee1d2ecba8]
./redis-server *:6379(aeMain+0x1d)[0x55ee1d2ed69d]
./redis-server *:6379(main+0x2e6)[0x55ee1d2e9156]
/usr/lib/libc.so.6(+0x29290)[0x7f56767c9290]
/usr/lib/libc.so.6(__libc_start_main+0x8a)[0x7f56767c934a]
./redis-server *:6379(_start+0x25)[0x55ee1d2e9695]

------ REGISTERS ------
1390:M 27 May 2022 11:23:56.999 # 
RAX:0000000000000000 RBX:00007f5676314000
RCX:0000000000000000 RDX:000000006290444c
RDI:00007f567620a9d8 RSI:0000000000000000
RBP:0000000000000000 RSP:00007ffdfe775748
R8 :0000000000000000 R9 :0000000000000000
R10:0000000000000000 R11:0000000000000000
R12:0000000000000000 R13:0005dff5d62fe3af
R14:00007f567631e600 R15:00007ffdfe7757a0
RIP:000055ee1d2efbfa EFL:0000000000010246
CSGSFS:002b000000000033
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775757) -> 00007f567622a190
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775756) -> a4f02e9b1df29700
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775755) -> 0000000000000000
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775754) -> 00000000000f38af
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775753) -> 000000006290444c
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775752) -> 0000000000000002
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775751) -> 0000000000000000
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775750) -> 000000001d2f0baf
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe77574f) -> 00007f567628c030
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe77574e) -> 000055ee1d2f58ee
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe77574d) -> 000000000000000f
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe77574c) -> 000055ee1d3315df
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe77574b) -> 0000000000000000
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe77574a) -> 000055ee1d51d4b0
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775749) -> 00007f567631e600
1390:M 27 May 2022 11:23:56.999 # (00007ffdfe775748) -> 000055ee1d31d711

------ CURRENT CLIENT INFO ------
id=3 addr=127.0.0.1:39650 laddr=127.0.0.1:6379 fd=8 name= age=27 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=29 qbuf-free=20445 argv-mem=13 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=22301 events=r cmd=getfirst user=default redir=-1 resp=2
argv[0]: '"getFirst"'
argv[1]: '"hello"'
1390:M 27 May 2022 11:23:56.999 # key 'hello' found in DB containing the following object:
1390:M 27 May 2022 11:23:56.999 # Object type: 0
1390:M 27 May 2022 11:23:56.999 # Object encoding: 8
1390:M 27 May 2022 11:23:56.999 # Object refcount: 1

想寻求一个 C 项目 bug 排查的思路,谢谢各位前辈

1982 次点击
所在节点    Redis
3 条回复
MoYi123
2022-05-27 11:40:21 +08:00
用 clion 把 redis 用 debug 模式跑起来
印象中我当时看的是这篇文章 https://www.modb.pro/db/73281

会用 gdb 就直接 gdb 吧
lbllol365
2022-05-27 11:42:42 +08:00
@MoYi123 好的好的,我去看看,谢谢前辈
Cyshall
2022-05-27 17:32:09 +08:00
加载下 core 文件,然后 bt 看下崩在哪。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/855634

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX