1 //===----------------------------------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
12 #include "abort_message.h"
15 # include <android/api-level.h>
16 # if __ANDROID_API__ >= 21
18 extern "C" void android_set_abort_message(const char* msg
);
21 # endif // __ANDROID_API__ >= 21
24 #if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
25 # include <CrashReporterClient.h>
26 # define _LIBCXXABI_USE_CRASHREPORTER_CLIENT
29 void abort_message(const char* format
, ...)
31 // Write message to stderr. We do this before formatting into a
32 // variable-size buffer so that we still get some information if
33 // formatting into the variable-sized buffer fails.
34 #if !defined(NDEBUG) || !defined(LIBCXXABI_BAREMETAL)
36 fprintf(stderr
, "libc++abi: ");
38 va_start(list
, format
);
39 vfprintf(stderr
, format
, list
);
41 fprintf(stderr
, "\n");
45 // Format the arguments into an allocated buffer. We leak the buffer on
46 // purpose, since we're about to abort() anyway.
47 #if defined(_LIBCXXABI_USE_CRASHREPORTER_CLIENT)
50 va_start(list
, format
);
51 vasprintf(&buffer
, format
, list
);
54 CRSetCrashLogMessage(buffer
);
55 #elif defined(__BIONIC__)
58 va_start(list
, format
);
59 vasprintf(&buffer
, format
, list
);
62 # if __ANDROID_API__ >= 21
63 // Show error in tombstone.
64 android_set_abort_message(buffer
);
66 // Show error in logcat.
67 openlog("libc++abi", 0, 0);
68 syslog(LOG_CRIT
, "%s", buffer
);
71 // The good error reporting wasn't available in Android until L. Since we're
72 // about to abort anyway, just call __assert2, which will log _somewhere_
73 // (tombstone and/or logcat) in older releases.
74 __assert2(__FILE__
, __LINE__
, __func__
, buffer
);
75 # endif // __ANDROID_API__ >= 21