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 #ifdef __BIONIC__ 16 #include <android/set_abort_message.h> 17 #include <syslog.h> 18 #endif 19 20 #pragma GCC visibility push(hidden) 21 22 #if __APPLE__ 23 # if defined(__has_include) && __has_include(<CrashReporterClient.h>) 24 # define HAVE_CRASHREPORTERCLIENT_H 1 25 # include <CrashReporterClient.h> 26 # endif 27 #endif 28 29 __attribute__((visibility("hidden"), noreturn)) 30 void abort_message(const char* format, ...) 31 { 32 // write message to stderr 33 #if __APPLE__ 34 fprintf(stderr, "libc++abi.dylib: "); 35 #endif 36 va_list list; 37 va_start(list, format); 38 vfprintf(stderr, format, list); 39 va_end(list); 40 fprintf(stderr, "\n"); 41 42 #if __APPLE__ && HAVE_CRASHREPORTERCLIENT_H 43 // record message in crash report 44 char* buffer; 45 va_list list2; 46 va_start(list2, format); 47 vasprintf(&buffer, format, list2); 48 va_end(list2); 49 CRSetCrashLogMessage(buffer); 50 #elif __BIONIC__ 51 char* buffer; 52 va_list list2; 53 va_start(list2, format); 54 vasprintf(&buffer, format, list2); 55 va_end(list2); 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 65 66 abort(); 67 } 68 69 #pragma GCC visibility pop 70