Skip to content

Commit b253705

Browse files
committed
[Build][Demangler] Enable crash reporter integration on Darwin.
Crash reporter integration was only enabled for iOS. Enable it for any Darwin platform, but disable it for the minimal build. Also fix up a couple of issues that popped up when it was enabled. rdar://89139049
1 parent 71efd95 commit b253705

File tree

7 files changed

+54
-39
lines changed

7 files changed

+54
-39
lines changed

Diff for: CMakeLists.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,15 @@ option(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS
327327
"If non-empty, when embedding the LLVM bitcode binary sections into the relevant binaries, pass in -bitcode_hide_symbols. Does nothing if SWIFT_EMBED_BITCODE_SECTION is set to false."
328328
FALSE)
329329

330+
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
331+
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default TRUE)
332+
else()
333+
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default FALSE)
334+
endif()
335+
330336
option(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT
331337
"Whether to enable CrashReporter integration"
332-
FALSE)
338+
"${SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default}")
333339

334340
set(SWIFT_DARWIN_XCRUN_TOOLCHAIN "XcodeDefault" CACHE STRING
335341
"The name of the toolchain to pass to 'xcrun'")

Diff for: include/swift/Demangling/Errors.h

-33
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,6 @@
4444
#endif
4545
#endif
4646

47-
#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT
48-
49-
#define CRASHREPORTER_ANNOTATIONS_VERSION 5
50-
#define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info"
51-
52-
struct crashreporter_annotations_t {
53-
uint64_t version; // unsigned long
54-
uint64_t message; // char *
55-
uint64_t signature_string; // char *
56-
uint64_t backtrace; // char *
57-
uint64_t message2; // char *
58-
uint64_t thread; // uint64_t
59-
uint64_t dialog_mode; // unsigned int
60-
uint64_t abort_cause; // unsigned int
61-
};
62-
63-
extern "C" {
64-
SWIFT_RUNTIME_LIBRARY_VISIBILITY
65-
extern struct crashreporter_annotations_t gCRAnnotations;
66-
}
67-
68-
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
69-
static inline void CRSetCrashLogMessage(const char *message) {
70-
gCRAnnotations.message = reinterpret_cast<uint64_t>(message);
71-
}
72-
73-
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
74-
static inline const char *CRGetCrashLogMessage() {
75-
return reinterpret_cast<const char *>(gCRAnnotations.message);
76-
}
77-
78-
#endif
79-
8047
namespace swift {
8148
namespace Demangle {
8249
SWIFT_BEGIN_INLINE_NAMESPACE

Diff for: lib/Demangling/Errors.cpp

+43-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,32 @@ static SWIFT_NORETURN void demangleFatal(uint32_t flags, const char *format,
4545
va_list val);
4646
static 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.
6795
static 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

156197
static SWIFT_NORETURN void demangleFatal(uint32_t flags, const char *format,

Diff for: unittests/runtime/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
122122
# and the stdlib.
123123
$<TARGET_OBJECTS:swiftRuntime${SWIFT_PRIMARY_VARIANT_SUFFIX}>
124124
$<TARGET_OBJECTS:swiftLLVMSupport${SWIFT_PRIMARY_VARIANT_SUFFIX}>
125-
$<TARGET_OBJECTS:swiftDemangling${SWIFT_PRIMARY_VARIANT_SUFFIX}>
125+
$<TARGET_OBJECTS:swiftDemanglingForCore${SWIFT_PRIMARY_VARIANT_SUFFIX}>
126126
)
127127

128128
# The local stdlib implementation provides definitions of the swiftCore

Diff for: unittests/runtime/LongTests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
4444
# and the stdlib.
4545
$<TARGET_OBJECTS:swiftRuntime${SWIFT_PRIMARY_VARIANT_SUFFIX}>
4646
$<TARGET_OBJECTS:swiftLLVMSupport${SWIFT_PRIMARY_VARIANT_SUFFIX}>
47-
$<TARGET_OBJECTS:swiftDemangling${SWIFT_PRIMARY_VARIANT_SUFFIX}>
47+
$<TARGET_OBJECTS:swiftDemanglingForCore${SWIFT_PRIMARY_VARIANT_SUFFIX}>
4848
)
4949

5050
# The local stdlib implementation provides definitions of the swiftCore

Diff for: utils/build-presets.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,7 @@ swift-stdlib-disable-instantiation-caches=1
25372537
swift-stdlib-has-type-printing=0
25382538
build-swift-stdlib-unicode-data=0
25392539
build-swift-stdlib-static-print=1
2540+
darwin-crash-reporter-client=0
25402541

25412542
[preset: stdlib_S_standalone_minimal_macho_x86_64,build]
25422543
mixin-preset=

Diff for: utils/build-script-impl

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ KNOWN_SETTINGS=(
9292
android-ndk "" "An absolute path to the NDK that will be used as a libc implementation for Android builds"
9393

9494
## Darwin Options
95-
darwin-crash-reporter-client "" "whether to enable CrashReporter integration"
95+
darwin-crash-reporter-client "" "whether to enable CrashReporter integration, default is 1 on Darwin platforms, 0 otherwise"
9696
darwin-deployment-version-ios "7.0" "minimum deployment target version for iOS"
9797
darwin-deployment-version-osx "10.9" "minimum deployment target version for OS X"
9898
darwin-deployment-version-tvos "9.0" "minimum deployment target version for tvOS"

0 commit comments

Comments
 (0)