// File: /workspace/github_c_makefile_star2_O2/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
callq 0x5892e
leaq 0x5ee73(%rip), %rsi     # 0xb80c0
leaq 0x57f85(%rip), %rdx     # 0xb11d9
pushq $0x3
popq %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2b699
testq %r14, %r14
je 0x59279
leaq 0x5ee73(%rip), %rsi     # 0xb80df
pushq $0x3
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2b699
cmpl $0xb, %ebx
je 0x59283
cmpl $0x7, %ebx
jne 0x59299
movq 0x10(%r12), %rdx
leaq 0x5ee76(%rip), %rsi     # 0xb8105
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
leaq 0xa0608(%rip), %rbp     # 0xf98a8
movq 0xa28(%rbp), %rdx
movq 0xa30(%rbp), %rcx
movl 0xa38(%rbp), %r8d
leaq 0x5ee5f(%rip), %rsi     # 0xb811b
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
leaq 0x5ee6b(%rip), %rsi     # 0xb8138
movl $0x403, %edi            # imm = 0x403
callq 0x2b51f
movq %r15, %rdi
callq 0x58d8e
leaq 0x5ee6e(%rip), %rsi     # 0xb8154
movl $0x403, %edi            # imm = 0x403
callq 0x2b51f
leaq 0x69417(%rip), %rdi     # 0xc270e
callq 0x2f3cf
movq %rax, %r12
callq 0x2a09a
leaq 0x5ee65(%rip), %rsi     # 0xb8170
movq %r12, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x31a38
movq %rax, %r12
movl $0x403, %edi            # imm = 0x403
movq %rax, %rsi
callq 0x2b51f
leaq 0x5ee57(%rip), %rsi     # 0xb8185
movl $0x403, %edi            # imm = 0x403
callq 0x2b51f
callq 0x3877b
movq %rax, %r13
movl $0x403, %edi            # imm = 0x403
movq %rax, %rsi
callq 0x2b51f
movq %r12, %rdi
callq 0x311c8
movq %r13, %rdi
callq 0x311c8
callq 0x58e20
movq %r15, %rdi
callq 0x58c24
leaq 0x5ee37(%rip), %rsi     # 0xb81a8
movl $0x403, %edi            # imm = 0x403
callq 0x2b51f
callq 0x66a16
callq 0x58f30
testl %eax, %eax
leaq 0x5ee72(%rip), %rax     # 0xb8200
leaq 0x5ee34(%rip), %rsi     # 0xb81c9
cmoveq %rax, %rsi
movl $0x403, %edi            # imm = 0x403
callq 0x2b51f
testq %r14, %r14
je 0x59441
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x26860
testl %eax, %eax
je 0x59441
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %r9
movq %rcx, (%rsp)
leaq 0x5ee9b(%rip), %rsi     # 0xb827b
movl $0x403, %edi            # imm = 0x403
xorl %eax, %eax
callq 0x2b699
movq %r14, %r15
subq 0x28(%rsp), %r15
pushq $0x1e
popq %rdi
callq 0x26410
cmpq $0x1fff, %r15           # imm = 0x1FFF
ja 0x59441
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 0x5ef18(%rip), %rsi     # 0xb8341
pushq $0x3
popq %rdi
movq %r14, %rcx
callq 0x594b8
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x5915a
leaq 0x5ef0a(%rip), %rsi     # 0xb8352
movl $0x403, %edi            # imm = 0x403
callq 0x2b51f
cmpl $0x0, 0x61c(%rbp)
je 0x5946d
cmpl $0x0, 0x614(%rbp)
jne 0x5946d
movq 0x60(%rbp), %rdi
callq 0x263b0
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x26ac0
movl $0xc8000000, 0x80(%r14) # imm = 0xC8000000
andq $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