[Clang] Make OpenMP offloading consistently use the bound architecture (#125135)
[llvm-project.git] / libcxx / src / verbose_abort.cpp
blobfd6bc4943d6babee3b9f93491c54162169ec4e0f
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include <__config>
10 #include <__verbose_abort>
11 #include <cstdarg>
12 #include <cstdio>
13 #include <cstdlib>
15 #ifdef __BIONIC__
16 # include <syslog.h>
17 extern "C" void android_set_abort_message(const char* msg);
18 #endif // __BIONIC__
20 #if defined(__APPLE__) && __has_include(<CrashReporterClient.h>)
21 # include <CrashReporterClient.h>
22 #endif
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.
30 va_list list;
31 va_start(list, format);
32 std::vfprintf(stderr, format, list);
33 va_end(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.
38 char* buffer;
39 (void)buffer;
40 va_list list;
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
46 // is low.
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);
58 closelog();
59 #endif
60 va_end(list);
62 std::abort();
65 _LIBCPP_END_NAMESPACE_STD