1 //===------------------------- abort_message.cpp --------------------------===// 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 #include "abort_message.h" 14 15 #pragma GCC visibility push(hidden) 16 17 #if __APPLE__ 18 # if defined(__has_include) && __has_include(<CrashReporterClient.h>) 19 # define HAVE_CRASHREPORTERCLIENT_H 1 20 # include <CrashReporterClient.h> 21 22 // If any clients of llvm try to link to libCrashReporterClient.a themselves, 23 // only one crash info struct will be used. 24 extern "C" { 25 CRASH_REPORTER_CLIENT_HIDDEN 26 struct crashreporter_annotations_t gCRAnnotations 27 __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) 28 = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 }; 29 } 30 31 # endif 32 #endif 33 34 __attribute__((visibility("hidden"), noreturn)) 35 void abort_message(const char* format, ...) 36 { 37 // write message to stderr 38 #if __APPLE__ 39 fprintf(stderr, "libc++abi.dylib: "); 40 #endif 41 va_list list; 42 va_start(list, format); 43 vfprintf(stderr, format, list); 44 va_end(list); 45 fprintf(stderr, "\n"); 46 47 #if __APPLE__ && HAVE_CRASHREPORTERCLIENT_H 48 // record message in crash report 49 char* buffer; 50 va_list list2; 51 va_start(list2, format); 52 vasprintf(&buffer, format, list2); 53 va_end(list2); 54 CRSetCrashLogMessage(buffer); 55 #endif 56 57 abort(); 58 } 59 60 #pragma GCC visibility pop 61