V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lbllol365
V2EX  ›  Redis

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

  •  
  •   lbllol365 · 2022-05-27 11:35:51 +08:00 · 1978 次点击
    这是一个创建于 901 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我这业余时间想试试开源项目,拉了 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 排查的思路,谢谢各位前辈

    3 条回复    2022-05-27 17:32:09 +08:00
    MoYi123
        1
    MoYi123  
       2022-05-27 11:40:21 +08:00   ❤️ 1
    用 clion 把 redis 用 debug 模式跑起来
    印象中我当时看的是这篇文章 https://www.modb.pro/db/73281

    会用 gdb 就直接 gdb 吧
    lbllol365
        2
    lbllol365  
    OP
       2022-05-27 11:42:42 +08:00
    @MoYi123 好的好的,我去看看,谢谢前辈
    Cyshall
        3
    Cyshall  
       2022-05-27 17:32:09 +08:00
    加载下 core 文件,然后 bt 看下崩在哪。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5755 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:35 · PVG 14:35 · LAX 22:35 · JFK 01:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.