// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0x9e579(%rip), %rbp     # 0x1018a8
cmpl $0x0, 0xa3c(%rbp)
jne 0x63353
leaq 0x63909(%rip), %rsi     # 0xc6c48
movl $0x403, %edi            # imm = 0x403
callq 0x2fc13
movl $0x1, 0xa3c(%rbp)
leaq 0x63b2a(%rip), %rsi     # 0xc6e84
leaq 0x5bf88(%rip), %rdx     # 0xbf2e9
movl $0x3, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2fdad
testq %r14, %r14
je 0x6338a
leaq 0x63b28(%rip), %rsi     # 0xc6ea3
movl $0x3, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2fdad
cmpl $0xb, %ebx
je 0x63394
cmpl $0x7, %ebx
jne 0x633ac
movq 0x10(%r12), %rdx
leaq 0x63b29(%rip), %rsi     # 0xc6ec9
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0xa28(%rbp), %rdx
movq 0xa30(%rbp), %rcx
movl 0xa38(%rbp), %r8d
leaq 0x63b17(%rip), %rsi     # 0xc6edf
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
leaq 0x63b21(%rip), %rsi     # 0xc6efc
movl $0x403, %edi            # imm = 0x403
callq 0x2fc13
movq %r15, %rdi
callq 0x62dbf
leaq 0x63b24(%rip), %rsi     # 0xc6f18
movl $0x403, %edi            # imm = 0x403
callq 0x2fc13
leaq 0x6e846(%rip), %rdi     # 0xd1c4b
callq 0x342b9
movq %rax, %r12
callq 0x2e5c6
leaq 0x63b1b(%rip), %rsi     # 0xc6f34
movq %r12, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x36f2d
movq %rax, %r12
movl $0x403, %edi            # imm = 0x403
movq %rax, %rsi
callq 0x2fc13
leaq 0x63b0d(%rip), %rsi     # 0xc6f49
movl $0x403, %edi            # imm = 0x403
callq 0x2fc13
callq 0x3ed94
movq %rax, %r13
movl $0x403, %edi            # imm = 0x403
movq %rax, %rsi
callq 0x2fc13
movq %r12, %rdi
callq 0x36330
movq %r13, %rdi
callq 0x36330
callq 0x62e94
movq %r15, %rdi
callq 0x62c2b
leaq 0x63aed(%rip), %rsi     # 0xc6f6c
movl $0x403, %edi            # imm = 0x403
callq 0x2fc13
callq 0x72617
callq 0x62fae
testl %eax, %eax
leaq 0x63b28(%rip), %rax     # 0xc6fc4
leaq 0x63aea(%rip), %rsi     # 0xc6f8d
cmoveq %rax, %rsi
movl $0x403, %edi            # imm = 0x403
callq 0x2fc13
testq %r14, %r14
je 0x63553
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x26860
testl %eax, %eax
je 0x63553
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
movq %rcx, (%rsp)
leaq 0x63b51(%rip), %rsi     # 0xc703f
movl $0x403, %edi            # imm = 0x403
xorl %eax, %eax
callq 0x2fdad
movq %r14, %r15
subq 0x28(%rsp), %r15
movl $0x1e, %edi
callq 0x26410
cmpq $0x1fff, %r15           # imm = 0x1FFF
ja 0x63553
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 0x63bcc(%rip), %rsi     # 0xc7105
movl $0x3, %edi
movq %r14, %rcx
callq 0x635cd
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x6323f
leaq 0x63bbc(%rip), %rsi     # 0xc7116
movl $0x403, %edi            # imm = 0x403
callq 0x2fc13
cmpl $0x0, 0x61c(%rbp)
je 0x6357f
cmpl $0x0, 0x614(%rbp)
jne 0x6357f
movq 0x60(%rbp), %rdi
callq 0x263b0
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x26ac0
movl $0xc8000000, 0x80(%r14) # imm = 0xC8000000
movq $0x0, -0x8(%r14)
leaq 0x10(%rsp), %rsi
movl %ebx, %edi
xorl %edx, %edx
callq 0x266c0
callq 0x26420
movl %eax, %edi
movl %ebx, %esi
callq 0x26660
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq