Пример #1
0
// where should this go...
extern "C" void abort() {
    static void (*libc_abort)() = (void (*)())dlsym(RTLD_NEXT, "abort");

    // In case something calls abort down the line:
    static bool recursive = false;
    if (!recursive) {
        recursive = true;

        fprintf(stderr, "Someone called abort!\n");

        // If we call abort(), things may be seriously wrong.  Set an alarm() to
        // try to handle cases that we would just hang.
        // (Ex if we abort() from a static constructor, and _printStackTrace uses
        // that object, _printStackTrace will hang waiting for the first construction
        // to finish.)
        alarm(1);
        try {
            _printStacktrace();
        } catch (ExcInfo) {
            fprintf(stderr, "error printing stack trace during abort()");
        }

        // Cancel the alarm.
        // This is helpful for when running in a debugger, since the debugger will catch the
        // abort and let you investigate, but the alarm will still come back to kill the program.
        alarm(0);
    }

    libc_abort();
    __builtin_unreachable();
}
Пример #2
0
// where should this go...
extern "C" void abort() {
    static void (*libc_abort)() = (void (*)())dlsym(RTLD_NEXT, "abort");

    // In case something calls abort down the line:
    static bool recursive = false;
    if (!recursive) {
        recursive = true;

        fprintf(stderr, "Someone called abort!\n");

        _printStacktrace();
    }

    libc_abort();
    __builtin_unreachable();
}