[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:
Alastair Houghton
2022-03-24 16:19:14 +00:00
parent 71efd95052
commit b253705fe8
7 changed files with 54 additions and 39 deletions

View File

@@ -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'")

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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

View File

@@ -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=

View File

@@ -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"