更新
我找到了OP中提到的debug.c行,我们可以从这段代码上面的两行看到:
redisLog(REDIS_WARNING,"(forcing SIGSEGV to print the bug report.)");
并且在_redisPanic中也可以找到相同的代码,因此当断言失败或出现恐慌时,它看起来像是强制SIGSEGV的方式.
原版的
这看起来像一个调试工具,我们可以从这个文档Redis debugging guide和相关部分看到:
Redis has a command to simulate a segmentation fault (in other words a bad crash) using the DEBUG SEGFAULT command (don’t use it against a real production instance of course ;). So I’ll use this command to crash my instance to show what happens in the GDB side:
并显示此gdb输出:
(gdb) continue
Continuing.
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xffffffffffffffff
debugCommand (c=0x7ffc32005000) at debug.c:220
220 *((char*)-1) = 'x';
^^^^^^^^^^^^^^^^^^^
它正在做的是将-1转换为* char **,然后对其执行间接操作并将“x”分配给该内存位置.由于链接Is ((void *) -1) a valid address?在大多数系统上所说的线程无法访问,更不用说分配值了.这将在大多数现代操作系统上生成segmentation fault.