// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/debug.c
// Function: sigsegvHandler
void sigsegvHandler(int sig, siginfo_t *info, void *secret) {
    ucontext_t *uc = (ucontext_t*) secret;
    sds infostring, clients;
    struct sigaction act;
    UNUSED(info);

    bugReportStart();
    serverLog(LL_WARNING,
        "    Discnt %s crashed by signal: %d", DISCNT_VERSION, sig);
    if (sig == SIGSEGV) {
        serverLog(LL_WARNING,
         "    SIGSEGV caused by 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 */
    serverLog(LL_WARNING, "--- STACK TRACE");
    logStackTrace(uc);

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

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

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

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

    serverLog(LL_WARNING,
"\n=== DISCNT 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/erikdubbelboer/discnt/issues\n\n"
"  Suspect RAM error? Use discnt-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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebx
leaq 0x43c2d(%rip), %r13     # 0x6f088
cmpl $0x0, 0x694(%r13)
jne 0x2b483
leaq 0x2afca(%rip), %rsi     # 0x56436
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
movl $0x1, 0x694(%r13)
leaq 0x2b149(%rip), %rsi     # 0x565d3
leaq 0x28c3c(%rip), %rdx     # 0x540cd
movl $0x3, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x19fb1
cmpl $0xb, %ebx
jne 0x2b4bb
movq 0x10(%r15), %rdx
leaq 0x2b148(%rip), %rsi     # 0x565f7
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
movq 0x680(%r13), %rdx
movq 0x688(%r13), %rcx
movl 0x690(%r13), %r8d
leaq 0x2b142(%rip), %rsi     # 0x56619
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
leaq 0x2b150(%rip), %rsi     # 0x5663a
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
movq %r14, %rdi
callq 0x2b02a
leaq 0x2b145(%rip), %rsi     # 0x5664a
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
leaq 0x2b09d(%rip), %rdi     # 0x565b5
callq 0x1c9d2
movq %rax, %r15
callq 0x187af
leaq 0x2b12e(%rip), %rsi     # 0x5665a
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x1eace
movq %rax, %r15
movl $0x3, %edi
movq %rax, %rsi
callq 0x19e3d
leaq 0x2b120(%rip), %rsi     # 0x5666f
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
callq 0x2428b
movq %rax, %r12
movl $0x3, %edi
movq %rax, %rsi
callq 0x19e3d
movq %r15, %rdi
callq 0x1ded3
movq %r12, %rdi
callq 0x1ded3
callq 0x2b0af
movq %r14, %rdi
callq 0x2aed8
leaq 0x2b0f2(%rip), %rsi     # 0x56686
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
callq 0x2f5d8
callq 0x2b168
testl %eax, %eax
leaq 0x2b11e(%rip), %rax     # 0x566d1
leaq 0x2b0e1(%rip), %rsi     # 0x5669b
cmoveq %rax, %rsi
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
leaq 0x2b17a(%rip), %rsi     # 0x5674b
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
cmpl $0x0, 0x5b8(%r13)
je 0x2b5fa
cmpl $0x0, 0x5b0(%r13)
jne 0x2b5fa
movq 0x50(%r13), %rdi
callq 0x120f0
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x124f0
movl $0xc8000000, 0x80(%r14) # imm = 0xC8000000
movq $0x0, -0x8(%r14)
leaq 0x8(%rsp), %rsi
movl %ebx, %edi
xorl %edx, %edx
callq 0x12170
callq 0x121f0
movl %eax, %edi
movl %ebx, %esi
callq 0x12540
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq