// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebx
callq 0x24147
leaq 0x2b495(%rip), %rsi     # 0x4fdd3
leaq 0x296ef(%rip), %rdx     # 0x4e034
pushq $0x3
popq %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x15b9e
cmpl $0xb, %ebx
jne 0x2496b
movq 0x10(%r15), %rdx
leaq 0x2b496(%rip), %rsi     # 0x4fdf7
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x15b9e
leaq 0x45716(%rip), %r13     # 0x6a088
movq 0x680(%r13), %rdx
movq 0x688(%r13), %rcx
movl 0x690(%r13), %r8d
leaq 0x2b48b(%rip), %rsi     # 0x4fe19
pushq $0x3
popq %rbp
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
leaq 0x2b499(%rip), %rsi     # 0x4fe3a
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
movq %r14, %rdi
callq 0x24549
leaq 0x2b491(%rip), %rsi     # 0x4fe4a
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
leaq 0x2b3ec(%rip), %rdi     # 0x4fdb5
callq 0x18187
movq %rax, %r15
callq 0x1458f
leaq 0x2b47d(%rip), %rsi     # 0x4fe5a
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x19db8
movq %rax, %r15
movl %ebp, %edi
movq %rax, %rsi
callq 0x15a3d
leaq 0x2b472(%rip), %rsi     # 0x4fe6f
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
callq 0x1e492
movq %rax, %r12
movl %ebp, %edi
movq %rax, %rsi
callq 0x15a3d
movq %r15, %rdi
callq 0x19548
movq %r12, %rdi
callq 0x19548
callq 0x245ca
movq %r14, %rdi
callq 0x2441e
leaq 0x2b44a(%rip), %rsi     # 0x4fe86
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
callq 0x2828c
callq 0x24676
testl %eax, %eax
leaq 0x2b479(%rip), %rax     # 0x4fed1
leaq 0x2b43c(%rip), %rsi     # 0x4fe9b
cmoveq %rax, %rsi
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
leaq 0x2b4d8(%rip), %rsi     # 0x4ff4b
movl %ebp, %edi
xorl %eax, %eax
callq 0x15b9e
cmpl $0x0, 0x5b8(%r13)
je 0x24a99
cmpl $0x0, 0x5b0(%r13)
jne 0x24a99
movq 0x50(%r13), %rdi
callq 0x120f0
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x124e0
movl $0xc8000000, 0x80(%r14) # imm = 0xC8000000
andq $0x0, -0x8(%r14)
movq %rsp, %rsi
movl %ebx, %edi
xorl %edx, %edx
callq 0x12170
callq 0x121f0
movl %eax, %edi
movl %ebx, %esi
callq 0x12530
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq