brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · d51d9d8 Raw
68 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include <stdlib.h>10#include <stdio.h>11#include <stdarg.h>12#include "abort_message.h"13 14#ifdef __BIONIC__15#  include <syslog.h>16extern "C" void android_set_abort_message(const char* msg);17#endif // __BIONIC__18 19#if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)20#   include <CrashReporterClient.h>21#   define _LIBCXXABI_USE_CRASHREPORTER_CLIENT22#endif23 24void __abort_message(const char* format, ...)25{26    // Write message to stderr. We do this before formatting into a27    // variable-size buffer so that we still get some information if28    // formatting into the variable-sized buffer fails.29#if !defined(NDEBUG) || !defined(LIBCXXABI_BAREMETAL)30    {31        fprintf(stderr, "libc++abi: ");32        va_list list;33        va_start(list, format);34        vfprintf(stderr, format, list);35        va_end(list);36        fprintf(stderr, "\n");37    }38#endif39 40    // Format the arguments into an allocated buffer. We leak the buffer on41    // purpose, since we're about to abort() anyway.42#if defined(_LIBCXXABI_USE_CRASHREPORTER_CLIENT)43    char* buffer;44    va_list list;45    va_start(list, format);46    vasprintf(&buffer, format, list);47    va_end(list);48 49    CRSetCrashLogMessage(buffer);50#elif defined(__BIONIC__)51    char* buffer;52    va_list list;53    va_start(list, format);54    vasprintf(&buffer, format, list);55    va_end(list);56 57    // Show error in tombstone.58    android_set_abort_message(buffer);59 60    // Show error in logcat.61    openlog("libc++abi", 0, 0);62    syslog(LOG_CRIT, "%s", buffer);63    closelog();64#endif // __BIONIC__65 66    abort();67}68