@@ -45,12 +45,32 @@ static SWIFT_NORETURN void demangleFatal(uint32_t flags, const char *format,
4545 va_list val);
4646static void demangleWarn (uint32_t flags, const char *format, va_list val);
4747
48+ static int demangle_vasprintf (char **strp, const char *format, va_list val);
49+
50+ #if SWIFT_HAVE_CRASHREPORTERCLIENT
51+ static int demangle_asprintf (char **strp, const char *format, ...);
52+ #endif
53+
4854// -- Crash reporter integration ---------------------------------------------
4955
5056#if SWIFT_HAVE_CRASHREPORTERCLIENT
5157#include < malloc/malloc.h>
5258#include < pthread.h>
5359
60+ #define CRASHREPORTER_ANNOTATIONS_VERSION 5
61+ #define CRASHREPORTER_ANNOTATIONS_SECTION " __crash_info"
62+
63+ struct crashreporter_annotations_t {
64+ uint64_t version; // unsigned long
65+ uint64_t message; // char *
66+ uint64_t signature_string; // char *
67+ uint64_t backtrace; // char *
68+ uint64_t message2; // char *
69+ uint64_t thread; // uint64_t
70+ uint64_t dialog_mode; // unsigned int
71+ uint64_t abort_cause; // unsigned int
72+ };
73+
5474// Instead of linking to CrashReporterClient.a (because it complicates the
5575// build system), define the only symbol from that static archive ourselves.
5676//
@@ -63,6 +83,14 @@ struct crashreporter_annotations_t gCRAnnotations __attribute__((
6383 CRASHREPORTER_ANNOTATIONS_VERSION, 0 , 0 , 0 , 0 , 0 , 0 , 0 };
6484}
6585
86+ static inline void CRSetCrashLogMessage (const char *message) {
87+ gCRAnnotations .message = reinterpret_cast <uint64_t >(message);
88+ }
89+
90+ static inline const char *CRGetCrashLogMessage () {
91+ return reinterpret_cast <const char *>(gCRAnnotations .message );
92+ }
93+
6694// Report a message to any forthcoming crash log.
6795static void reportOnCrash (uint32_t flags, const char *message) {
6896 // We must use an "unsafe" mutex in this pathway since the normal "safe"
@@ -73,10 +101,10 @@ static void reportOnCrash(uint32_t flags, const char *message) {
73101
74102 pthread_mutex_lock (&crashlogLock);
75103
76- char *oldMessage = ( char *) CRGetCrashLogMessage ();
104+ char *oldMessage = const_cast < char *>( CRGetCrashLogMessage () );
77105 char *newMessage;
78106 if (oldMessage) {
79- swift_asprintf (&newMessage, " %s%s" , oldMessage, message);
107+ demangle_asprintf (&newMessage, " %s%s" , oldMessage, message);
80108 if (malloc_size (oldMessage))
81109 free (oldMessage);
82110 } else {
@@ -151,6 +179,19 @@ static int demangle_vasprintf(char **strp, const char *format, va_list args) {
151179 return result;
152180}
153181
182+ #if SWIFT_HAVE_CRASHREPORTERCLIENT
183+ SWIFT_FORMAT (2 ,3 )
184+ static int demangle_asprintf(char **strp, const char *format, ...) {
185+ va_list val;
186+
187+ va_start (val, format);
188+ int ret = demangle_vasprintf (strp, format, val);
189+ va_end (val);
190+
191+ return ret;
192+ }
193+ #endif // SWIFT_HAVE_CRASHREPORTERCLIENT
194+
154195// -- Implementation ---------------------------------------------------------
155196
156197static SWIFT_NORETURN void demangleFatal (uint32_t flags, const char *format,
0 commit comments