|
| 1 | +//===-------------------------- abort_message.c ---------------------------===// |
| 2 | +// |
| 3 | +// The LLVM Compiler Infrastructure |
| 4 | +// |
| 5 | +// This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | +// Source Licenses. See LICENSE.TXT for details. |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#include <stdlib.h> |
| 11 | +#include <stdio.h> |
| 12 | +#include <stdarg.h> |
| 13 | + |
| 14 | +#if __APPLE__ |
| 15 | + #include <Availability.h> |
| 16 | + #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 |
| 17 | + #include <CrashReporterClient.h> |
| 18 | + |
| 19 | + // If any clients of llvm try to link to libCrashReporterClient.a themselves, |
| 20 | + // only one crash info struct will be used. |
| 21 | + extern "C" { |
| 22 | + CRASH_REPORTER_CLIENT_HIDDEN |
| 23 | + struct crashreporter_annotations_t gCRAnnotations |
| 24 | + __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) |
| 25 | + = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 }; |
| 26 | + } |
| 27 | + |
| 28 | + #endif |
| 29 | +#endif |
| 30 | + |
| 31 | +#include "abort_message.h" |
| 32 | + |
| 33 | +__attribute__((visibility("hidden"))) |
| 34 | +void abort_message(const char* format, ...) |
| 35 | +{ |
| 36 | + // write message to stderr |
| 37 | +#if __APPLE__ |
| 38 | + fprintf(stderr, "libc++abi.dylib: "); |
| 39 | +#endif |
| 40 | + va_list list; |
| 41 | + va_start(list, format); |
| 42 | + vfprintf(stderr, format, list); |
| 43 | + va_end(list); |
| 44 | + fprintf(stderr, "\n"); |
| 45 | + |
| 46 | +#if __APPLE__ && (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1070) |
| 47 | + // record message in crash report |
| 48 | + char* buffer; |
| 49 | + va_list list2; |
| 50 | + va_start(list2, format); |
| 51 | + vasprintf(&buffer, format, list2); |
| 52 | + va_end(list2); |
| 53 | + CRSetCrashLogMessage(buffer); |
| 54 | +#endif |
| 55 | + |
| 56 | + abort(); |
| 57 | +} |
| 58 | + |
0 commit comments