diff --git a/stdlib/runtime/Debug.h b/stdlib/runtime/Debug.h index f00dd246600..802d624f7dd 100644 --- a/stdlib/runtime/Debug.h +++ b/stdlib/runtime/Debug.h @@ -28,6 +28,9 @@ namespace swift { +// swift::crash() halts with a crash log message, +// but otherwise tries not to disturb register state. + LLVM_ATTRIBUTE_NORETURN LLVM_ATTRIBUTE_ALWAYS_INLINE // Minimize trashed registers static void crash(const char *message) { @@ -41,6 +44,12 @@ static void crash(const char *message) { __builtin_unreachable(); } +// swift::fatalError() halts with a crash log message, +// but makes no attempt to preserve register state. +LLVM_ATTRIBUTE_NORETURN +extern void +fatalError(const char *format, ...); + }; #endif // _SWIFT_RUNTIME_DEBUG_HELPERS_ diff --git a/stdlib/runtime/Errors.cpp b/stdlib/runtime/Errors.cpp index 33e223a1480..a4e239c6a37 100644 --- a/stdlib/runtime/Errors.cpp +++ b/stdlib/runtime/Errors.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "Debug.h" #if SWIFT_HAVE_CRASHREPORTERCLIENT @@ -70,6 +71,24 @@ reportNow(const char *message) } +// Report a fatal error to system console, stderr, and crash logs, then abort. +LLVM_ATTRIBUTE_NORETURN +void +swift::fatalError(const char *format, ...) +{ + va_list args; + va_start(args, format); + + char *log; + vasprintf(&log, format, args); + + reportNow(log); + reportOnCrash(log); + + abort(); +} + + // Report a fatal error to system console, stderr, and crash logs. // : : file , line \n // The message may be omitted by passing messageLength=0. diff --git a/stdlib/runtime/SwiftObject.mm b/stdlib/runtime/SwiftObject.mm index a4c27e7a8d2..1af97ca2ee1 100644 --- a/stdlib/runtime/SwiftObject.mm +++ b/stdlib/runtime/SwiftObject.mm @@ -182,7 +182,10 @@ static NSString *_getDescription(SwiftObject *obj) { } - (void)doesNotRecognizeSelector: (SEL) sel { - swift::crash("Unrecognized selector"); + Class cls = object_getClass(self); + fatalError("Unrecognized selector %c[%s %s]\n", + class_isMetaClass(cls) ? '+' : '-', + class_getName(cls), sel_getName(sel)); } - (id)retain {