// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/debug.c
// Function: sigsegvHandler
void sigsegvHandler(int sig, siginfo_t *info, void *secret) {
    ucontext_t *uc = (ucontext_t*) secret;
    void *eip = getMcontextEip(uc);
    sds infostring, clients;
    struct sigaction act;
    UNUSED(info);

    bugReportStart();
    serverLog(LL_WARNING,
        "Redis %s crashed by signal: %d", REDIS_VERSION, sig);
    if (eip != NULL) {
        serverLog(LL_WARNING,
        "Crashed running the instuction at: %p", eip);
    }
    if (sig == SIGSEGV || sig == SIGBUS) {
        serverLog(LL_WARNING,
        "Accessing address: %p", (void*)info->si_addr);
    }
    serverLog(LL_WARNING,
        "Failed assertion: %s (%s:%d)", server.assert_failed,
                        server.assert_file, server.assert_line);

    /* Log the stack trace */
    serverLogRaw(LL_WARNING|LL_RAW, "\n------ STACK TRACE ------\n");
    logStackTrace(uc);

    /* Log INFO and CLIENT LIST */
    serverLogRaw(LL_WARNING|LL_RAW, "\n------ INFO OUTPUT ------\n");
    infostring = genRedisInfoString("all");
    infostring = sdscatprintf(infostring, "hash_init_value: %u\n",
        dictGetHashFunctionSeed());
    serverLogRaw(LL_WARNING|LL_RAW, infostring);
    serverLogRaw(LL_WARNING|LL_RAW, "\n------ CLIENT LIST OUTPUT ------\n");
    clients = getAllClientsInfoString();
    serverLogRaw(LL_WARNING|LL_RAW, clients);
    sdsfree(infostring);
    sdsfree(clients);

    /* Log the current client */
    logCurrentClient();

    /* Log dump of processor registers */
    logRegisters(uc);

#if defined(HAVE_PROC_MAPS)
    /* Test memory */
    serverLogRaw(LL_WARNING|LL_RAW, "\n------ FAST MEMORY TEST ------\n");
    bioKillThreads();
    if (memtest_test_linux_anonymous_maps()) {
        serverLogRaw(LL_WARNING|LL_RAW,
            "!!! MEMORY ERROR DETECTED! Check your memory ASAP !!!\n");
    } else {
        serverLogRaw(LL_WARNING|LL_RAW,
            "Fast memory test PASSED, however your memory can still be broken. Please run a memory test for several hours if possible.\n");
    }
#endif

    if (eip != NULL) {
        Dl_info info;
        if (dladdr(eip, &info) != 0) {
            serverLog(LL_WARNING|LL_RAW,
                "\n------ DUMPING CODE AROUND EIP ------\n"
                "Symbol: %s (base: %p)\n"
                "Module: %s (base %p)\n"
                "$ xxd -r -p /tmp/dump.hex /tmp/dump.bin\n"
                "$ objdump --adjust-vma=%p -D -b binary -m i386:x86-64 /tmp/dump.bin\n"
                "------\n",
                info.dli_sname, info.dli_saddr, info.dli_fname, info.dli_fbase,
                info.dli_saddr);
            size_t len = (long)eip - (long)info.dli_saddr;
            unsigned long sz = sysconf(_SC_PAGESIZE);
            if (len < 1<<13) { /* we don't have functions over 8k (verified) */
                /* Find the address of the next page, which is our "safety"
                 * limit when dumping. Then try to dump just 128 bytes more
                 * than EIP if there is room, or stop sooner. */
                unsigned long next = ((unsigned long)eip + sz) & ~(sz-1);
                unsigned long end = (unsigned long)eip + 128;
                if (end > next) end = next;
                len = end - (unsigned long)info.dli_saddr;
                serverLogHexDump(LL_WARNING, "dump of function",
                    info.dli_saddr ,len);
                dumpX86Calls(info.dli_saddr,len);
            }
        }
    }

    serverLogRaw(LL_WARNING|LL_RAW,
"\n=== REDIS BUG REPORT END. Make sure to include from START to END. ===\n\n"
"       Please report the crash by opening an issue on github:\n\n"
"           http://github.com/antirez/redis/issues\n\n"
"  Suspect RAM error? Use redis-server --test-memory to verify it.\n\n"
);

    /* free(messages); Don't call free() with possibly corrupted memory. */
    if (server.daemonize && server.supervised == 0) unlink(server.pidfile);

    /* Make sure we exit with the right signal at the end. So for instance
     * the core will be dumped if enabled. */
    sigemptyset (&act.sa_mask);
    act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND;
    act.sa_handler = SIG_DFL;
    sigaction (sig, &act, NULL);
    kill(getpid(),sig);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %r15
movq %rsi, %r12
movl %edi, %ebx
movq 0xa8(%rdx), %r14
leaq 0x9f912(%rip), %rbp     # 0x106858
cmpl $0x0, 0xa2c(%rbp)
jne 0x66f6a
leaq 0x62c96(%rip), %rsi     # 0xc9bec
movl $0x403, %edi            # imm = 0x403
callq 0x32d0c
movl $0x1, 0xa2c(%rbp)
leaq 0x62eb7(%rip), %rsi     # 0xc9e28
leaq 0x5b308(%rip), %rdx     # 0xc2280
movl $0x3, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x32ea6
testq %r14, %r14
je 0x66fa1
leaq 0x62eb5(%rip), %rsi     # 0xc9e47
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x32ea6
cmpl $0xb, %ebx
je 0x66fab
cmpl $0x7, %ebx
jne 0x66fc3
movq 0x10(%r12), %rdx
leaq 0x62eb6(%rip), %rsi     # 0xc9e6d
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0xa18(%rbp), %rdx
movq 0xa20(%rbp), %rcx
movl 0xa28(%rbp), %r8d
leaq 0x62ea4(%rip), %rsi     # 0xc9e83
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
leaq 0x62eae(%rip), %rsi     # 0xc9ea0
movl $0x403, %edi            # imm = 0x403
callq 0x32d0c
movq %r15, %rdi
callq 0x669cc
leaq 0x62eb1(%rip), %rsi     # 0xc9ebc
movl $0x403, %edi            # imm = 0x403
callq 0x32d0c
leaq 0x6dacf(%rip), %rdi     # 0xd4aeb
callq 0x372d4
movq %rax, %r12
callq 0x316ae
leaq 0x62ea8(%rip), %rsi     # 0xc9ed8
movq %r12, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x39eb7
movq %rax, %r12
movl $0x403, %edi            # imm = 0x403
movq %rax, %rsi
callq 0x32d0c
leaq 0x62e9a(%rip), %rsi     # 0xc9eed
movl $0x403, %edi            # imm = 0x403
callq 0x32d0c
callq 0x42167
movq %rax, %r13
movl $0x403, %edi            # imm = 0x403
movq %rax, %rsi
callq 0x32d0c
movq %r12, %rdi
callq 0x392b6
movq %r13, %rdi
callq 0x392b6
callq 0x66a9e
movq %r15, %rdi
callq 0x66838
leaq 0x62e7a(%rip), %rsi     # 0xc9f10
movl $0x403, %edi            # imm = 0x403
callq 0x32d0c
callq 0x760cb
callq 0x66bb8
testl %eax, %eax
leaq 0x62eb5(%rip), %rax     # 0xc9f68
leaq 0x62e77(%rip), %rsi     # 0xc9f31
cmoveq %rax, %rsi
movl $0x403, %edi            # imm = 0x403
callq 0x32d0c
testq %r14, %r14
je 0x6716a
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x26870
testl %eax, %eax
je 0x6716a
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
movq %rcx, (%rsp)
leaq 0x62ede(%rip), %rsi     # 0xc9fe3
movl $0x403, %edi            # imm = 0x403
xorl %eax, %eax
callq 0x32ea6
movq %r14, %r15
subq 0x28(%rsp), %r15
movl $0x1e, %edi
callq 0x26420
cmpq $0x1fff, %r15           # imm = 0x1FFF
ja 0x6716a
leaq (%rax,%r14), %rcx
negq %rax
andq %rcx, %rax
subq $-0x80, %r14
cmpq %rax, %r14
cmovaeq %rax, %r14
movq 0x28(%rsp), %rdx
subq %rdx, %r14
leaq 0x62f59(%rip), %rsi     # 0xca0a9
movl $0x3, %edi
movq %r14, %rcx
callq 0x671e4
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x66e50
leaq 0x62f49(%rip), %rsi     # 0xca0ba
movl $0x403, %edi            # imm = 0x403
callq 0x32d0c
cmpl $0x0, 0x60c(%rbp)
je 0x67196
cmpl $0x0, 0x604(%rbp)
jne 0x67196
movq 0x60(%rbp), %rdi
callq 0x263c0
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x26ad0
movl $0xc8000000, 0x80(%r14) # imm = 0xC8000000
movq $0x0, -0x8(%r14)
leaq 0x10(%rsp), %rsi
movl %ebx, %edi
xorl %edx, %edx
callq 0x266d0
callq 0x26430
movl %eax, %edi
movl %ebx, %esi
callq 0x26670
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq