mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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
This commit is contained in:
@@ -327,9 +327,15 @@ option(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS
|
||||
"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."
|
||||
FALSE)
|
||||
|
||||
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
|
||||
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default TRUE)
|
||||
else()
|
||||
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default FALSE)
|
||||
endif()
|
||||
|
||||
option(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT
|
||||
"Whether to enable CrashReporter integration"
|
||||
FALSE)
|
||||
"${SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default}")
|
||||
|
||||
set(SWIFT_DARWIN_XCRUN_TOOLCHAIN "XcodeDefault" CACHE STRING
|
||||
"The name of the toolchain to pass to 'xcrun'")
|
||||
|
||||
@@ -44,39 +44,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SWIFT_HAVE_CRASHREPORTERCLIENT
|
||||
|
||||
#define CRASHREPORTER_ANNOTATIONS_VERSION 5
|
||||
#define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info"
|
||||
|
||||
struct crashreporter_annotations_t {
|
||||
uint64_t version; // unsigned long
|
||||
uint64_t message; // char *
|
||||
uint64_t signature_string; // char *
|
||||
uint64_t backtrace; // char *
|
||||
uint64_t message2; // char *
|
||||
uint64_t thread; // uint64_t
|
||||
uint64_t dialog_mode; // unsigned int
|
||||
uint64_t abort_cause; // unsigned int
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
SWIFT_RUNTIME_LIBRARY_VISIBILITY
|
||||
extern struct crashreporter_annotations_t gCRAnnotations;
|
||||
}
|
||||
|
||||
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
|
||||
static inline void CRSetCrashLogMessage(const char *message) {
|
||||
gCRAnnotations.message = reinterpret_cast<uint64_t>(message);
|
||||
}
|
||||
|
||||
SWIFT_RUNTIME_ATTRIBUTE_ALWAYS_INLINE
|
||||
static inline const char *CRGetCrashLogMessage() {
|
||||
return reinterpret_cast<const char *>(gCRAnnotations.message);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
namespace swift {
|
||||
namespace Demangle {
|
||||
SWIFT_BEGIN_INLINE_NAMESPACE
|
||||
|
||||
@@ -45,12 +45,32 @@ static SWIFT_NORETURN void demangleFatal(uint32_t flags, const char *format,
|
||||
va_list val);
|
||||
static void demangleWarn(uint32_t flags, const char *format, va_list val);
|
||||
|
||||
static int demangle_vasprintf(char **strp, const char *format, va_list val);
|
||||
|
||||
#if SWIFT_HAVE_CRASHREPORTERCLIENT
|
||||
static int demangle_asprintf(char **strp, const char *format, ...);
|
||||
#endif
|
||||
|
||||
// -- Crash reporter integration ---------------------------------------------
|
||||
|
||||
#if SWIFT_HAVE_CRASHREPORTERCLIENT
|
||||
#include <malloc/malloc.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define CRASHREPORTER_ANNOTATIONS_VERSION 5
|
||||
#define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info"
|
||||
|
||||
struct crashreporter_annotations_t {
|
||||
uint64_t version; // unsigned long
|
||||
uint64_t message; // char *
|
||||
uint64_t signature_string; // char *
|
||||
uint64_t backtrace; // char *
|
||||
uint64_t message2; // char *
|
||||
uint64_t thread; // uint64_t
|
||||
uint64_t dialog_mode; // unsigned int
|
||||
uint64_t abort_cause; // unsigned int
|
||||
};
|
||||
|
||||
// Instead of linking to CrashReporterClient.a (because it complicates the
|
||||
// build system), define the only symbol from that static archive ourselves.
|
||||
//
|
||||
@@ -63,6 +83,14 @@ struct crashreporter_annotations_t gCRAnnotations __attribute__((
|
||||
CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0};
|
||||
}
|
||||
|
||||
static inline void CRSetCrashLogMessage(const char *message) {
|
||||
gCRAnnotations.message = reinterpret_cast<uint64_t>(message);
|
||||
}
|
||||
|
||||
static inline const char *CRGetCrashLogMessage() {
|
||||
return reinterpret_cast<const char *>(gCRAnnotations.message);
|
||||
}
|
||||
|
||||
// Report a message to any forthcoming crash log.
|
||||
static void reportOnCrash(uint32_t flags, const char *message) {
|
||||
// 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) {
|
||||
|
||||
pthread_mutex_lock(&crashlogLock);
|
||||
|
||||
char *oldMessage = (char *)CRGetCrashLogMessage();
|
||||
char *oldMessage = const_cast<char *>(CRGetCrashLogMessage());
|
||||
char *newMessage;
|
||||
if (oldMessage) {
|
||||
swift_asprintf(&newMessage, "%s%s", oldMessage, message);
|
||||
demangle_asprintf(&newMessage, "%s%s", oldMessage, message);
|
||||
if (malloc_size(oldMessage))
|
||||
free(oldMessage);
|
||||
} else {
|
||||
@@ -151,6 +179,19 @@ static int demangle_vasprintf(char **strp, const char *format, va_list args) {
|
||||
return result;
|
||||
}
|
||||
|
||||
#if SWIFT_HAVE_CRASHREPORTERCLIENT
|
||||
SWIFT_FORMAT(2,3)
|
||||
static int demangle_asprintf(char **strp, const char *format, ...) {
|
||||
va_list val;
|
||||
|
||||
va_start(val, format);
|
||||
int ret = demangle_vasprintf(strp, format, val);
|
||||
va_end(val);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif // SWIFT_HAVE_CRASHREPORTERCLIENT
|
||||
|
||||
// -- Implementation ---------------------------------------------------------
|
||||
|
||||
static SWIFT_NORETURN void demangleFatal(uint32_t flags, const char *format,
|
||||
|
||||
@@ -122,7 +122,7 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
|
||||
# and the stdlib.
|
||||
$<TARGET_OBJECTS:swiftRuntime${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
$<TARGET_OBJECTS:swiftLLVMSupport${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
$<TARGET_OBJECTS:swiftDemangling${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
$<TARGET_OBJECTS:swiftDemanglingForCore${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
)
|
||||
|
||||
# The local stdlib implementation provides definitions of the swiftCore
|
||||
|
||||
@@ -44,7 +44,7 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
|
||||
# and the stdlib.
|
||||
$<TARGET_OBJECTS:swiftRuntime${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
$<TARGET_OBJECTS:swiftLLVMSupport${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
$<TARGET_OBJECTS:swiftDemangling${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
$<TARGET_OBJECTS:swiftDemanglingForCore${SWIFT_PRIMARY_VARIANT_SUFFIX}>
|
||||
)
|
||||
|
||||
# The local stdlib implementation provides definitions of the swiftCore
|
||||
|
||||
@@ -2537,6 +2537,7 @@ swift-stdlib-disable-instantiation-caches=1
|
||||
swift-stdlib-has-type-printing=0
|
||||
build-swift-stdlib-unicode-data=0
|
||||
build-swift-stdlib-static-print=1
|
||||
darwin-crash-reporter-client=0
|
||||
|
||||
[preset: stdlib_S_standalone_minimal_macho_x86_64,build]
|
||||
mixin-preset=
|
||||
|
||||
@@ -92,7 +92,7 @@ KNOWN_SETTINGS=(
|
||||
android-ndk "" "An absolute path to the NDK that will be used as a libc implementation for Android builds"
|
||||
|
||||
## Darwin Options
|
||||
darwin-crash-reporter-client "" "whether to enable CrashReporter integration"
|
||||
darwin-crash-reporter-client "" "whether to enable CrashReporter integration, default is 1 on Darwin platforms, 0 otherwise"
|
||||
darwin-deployment-version-ios "7.0" "minimum deployment target version for iOS"
|
||||
darwin-deployment-version-osx "10.9" "minimum deployment target version for OS X"
|
||||
darwin-deployment-version-tvos "9.0" "minimum deployment target version for tvOS"
|
||||
|
||||
Reference in New Issue
Block a user