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