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>
17 extern "C" void android_set_abort_message(const char* msg
);
20 #if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
21 # include <CrashReporterClient.h>
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 _LIBCPP_WEAK
void __libcpp_verbose_abort(char const* format
, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT
{
27 // Write message to stderr. We do this before formatting into a
28 // buffer so that we still get some information out if that fails.
31 va_start(list
, format
);
32 std::vfprintf(stderr
, format
, list
);
36 // Format the arguments into an allocated buffer for CrashReport & friends.
37 // We leak the buffer on purpose, since we're about to abort() anyway.
41 va_start(list
, format
);
43 #if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
44 // Note that we should technically synchronize accesses here (by e.g. taking a lock),
45 // however concretely we're only setting a pointer, so the likelihood of a race here
47 vasprintf(&buffer
, format
, list
);
48 CRSetCrashLogMessage(buffer
);
49 #elif defined(__BIONIC__)
50 vasprintf(&buffer
, format
, list
);
52 // Show error in tombstone.
53 android_set_abort_message(buffer
);
55 // Show error in logcat.
56 openlog("libc++", 0, 0);
57 syslog(LOG_CRIT
, "%s", buffer
);
65 _LIBCPP_END_NAMESPACE_STD