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 //===----------------------------------------------------------------------===//
10 #include <__verbose_abort>
16 # include <android/api-level.h>
17 # if __ANDROID_API__ >= 21
19 extern "C" void android_set_abort_message(const char* msg
);
22 # endif // __ANDROID_API__ >= 21
25 #if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
26 # include <CrashReporterClient.h>
29 _LIBCPP_BEGIN_NAMESPACE_STD
32 void __libcpp_verbose_abort(char const* format
, ...) {
33 // Write message to stderr. We do this before formatting into a
34 // buffer so that we still get some information out if that fails.
37 va_start(list
, format
);
38 std::vfprintf(stderr
, format
, list
);
42 // Format the arguments into an allocated buffer for CrashReport & friends.
43 // We leak the buffer on purpose, since we're about to abort() anyway.
44 char* buffer
; (void)buffer
;
46 va_start(list
, format
);
48 #if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
49 // Note that we should technically synchronize accesses here (by e.g. taking a lock),
50 // however concretely we're only setting a pointer, so the likelihood of a race here
52 vasprintf(&buffer
, format
, list
);
53 CRSetCrashLogMessage(buffer
);
54 #elif defined(__BIONIC__)
55 vasprintf(&buffer
, format
, list
);
57 # if __ANDROID_API__ >= 21
58 // Show error in tombstone.
59 android_set_abort_message(buffer
);
61 // Show error in logcat.
62 openlog("libc++", 0, 0);
63 syslog(LOG_CRIT
, "%s", buffer
);
66 // The good error reporting wasn't available in Android until L. Since we're
67 // about to abort anyway, just call __assert2, which will log _somewhere_
68 // (tombstone and/or logcat) in older releases.
69 __assert2(__FILE__
, __LINE__
, __func__
, buffer
);
70 # endif // __ANDROID_API__ >= 21
77 _LIBCPP_END_NAMESPACE_STD