Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Catalyst support to Crashes #2063

Merged
merged 17 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#import "MSAppCenterInternal.h"
#import "MSCrashesInternal.h"
#import "MSCrashesUtil.h"
#import "MSException.h"
#import "MSLoggerInternal.h"
#import "MSUtility+File.h"
#import "MSWrapperExceptionInternal.h"
#import "MSWrapperExceptionManagerInternal.h"
Expand Down Expand Up @@ -84,7 +86,7 @@ + (void)correlateLastSavedWrapperExceptionToReport:(NSArray<MSErrorReport *> *)r
+ (void)saveWrapperException:(MSWrapperException *)wrapperException withBaseFilename:(NSString *)baseFilename {

// For some reason, archiving directly to a file fails in some cases, so archive to NSData and write that to the file
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:wrapperException];
NSData *data = [MSUtility archiveKeyedData:wrapperException];
NSString *pathComponent = [NSString stringWithFormat:@"%@/%@", [MSCrashesUtil wrapperExceptionsDir], baseFilename];
[MSUtility createFileAtPathComponent:pathComponent withData:data atomically:YES forceOverwrite:YES];
}
Expand All @@ -106,9 +108,13 @@ + (MSWrapperException *)loadWrapperExceptionWithBaseFilename:(NSString *)baseFil
NSString *pathComponent = [NSString stringWithFormat:@"%@/%@", [MSCrashesUtil wrapperExceptionsDir], baseFilename];
NSData *data = [MSUtility loadDataForPathComponent:pathComponent];
MSWrapperException *wrapperException = nil;
NSException *exception = nil;
@try {
wrapperException = [NSKeyedUnarchiver unarchiveObjectWithData:data];
} @catch (__attribute__((unused)) NSException *exception) {
wrapperException = (MSWrapperException *)[MSUtility unarchiveKeyedData:data];
} @catch (NSException *e) {
exception = e;
}
if (!wrapperException || exception) {
MSLogError([MSCrashes logTag], @"Could not read exception data stored on disk with file name %@", baseFilename);
[self deleteWrapperExceptionWithBaseFilename:baseFilename];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ + (MSAppleErrorLog *)addProcessInfoAndApplicationPathTo:(MSAppleErrorLog *)error
NSString *processPath = crashReport.processInfo.processPath;

// Remove username from the path
#if TARGET_OS_SIMULATOR || TARGET_OS_OSX
#if TARGET_OS_SIMULATOR || TARGET_OS_OSX || TARGET_OS_MACCATALYST
processPath = [self anonymizedPathFromPath:processPath];
#endif
errorLog.applicationPath = processPath;
Expand Down Expand Up @@ -590,7 +590,7 @@ + (NSString *)selectorRegisterValueFromReport:(PLCrashReport *)report
imagePath = imageInfo.imageName;
#endif
}
#if TARGET_OS_SIMULATOR || TARGET_OS_OSX
#if TARGET_OS_SIMULATOR || TARGET_OS_OSX || TARGET_OS_MACCATALYST
imagePath = [self anonymizedPathFromPath:imagePath];
#endif

Expand Down Expand Up @@ -827,7 +827,7 @@ + (NSString *)uuidRefToString:(CFUUIDRef)uuidRef {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
+ (uint64_t)normalizeAddress:(uint64_t)address is64bit:(BOOL)is64bit {
#if TARGET_OS_OSX
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
return address;
#else
return is64bit ? address & 0x0000000fffffffff : address;
Expand Down
2 changes: 1 addition & 1 deletion AppCenterCrashes/AppCenterCrashes/MSCrashes.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ typedef NS_ENUM(NSUInteger, MSUserConfirmation) {
*/
+ (nullable MSErrorReport *)lastSessionCrashReport;

#if TARGET_OS_OSX
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
/**
* Callback for report exception.
*
Expand Down
28 changes: 24 additions & 4 deletions AppCenterCrashes/AppCenterCrashes/MSCrashes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "MSErrorAttachmentLogInternal.h"
#import "MSErrorLogFormatter.h"
#import "MSErrorReportPrivate.h"
#import "MSLoggerInternal.h"
#import "MSHandledErrorLog.h"
#import "MSSessionContext.h"
#import "MSUserIdContext.h"
Expand Down Expand Up @@ -354,7 +355,7 @@ - (void)applyEnabledState:(BOOL)isEnabled {
#endif

// Set up memory warning handler.
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_MACCATALYST
if (MS_IS_APP_EXTENSION) {
#endif
self.memoryPressureSource =
Expand All @@ -366,7 +367,7 @@ - (void)applyEnabledState:(BOOL)isEnabled {
[strongSelf didReceiveMemoryWarning:nil];
});
dispatch_resume(self.memoryPressureSource);
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_MACCATALYST
} else {
[MS_NOTIFICATION_CENTER addObserver:self
selector:@selector(didReceiveMemoryWarning:)
Expand Down Expand Up @@ -526,7 +527,7 @@ - (void)channel:(id<MSChannelProtocol>)__unused channel

// The callback can be called from any thread, making sure we make this thread-safe.
@synchronized(self) {
NSData *serializedLog = [NSKeyedArchiver archivedDataWithRootObject:log];
NSData *serializedLog = [MSUtility archiveKeyedData:log];
if (serializedLog && (serializedLog.length > 0)) {

// Serialize target token.
Expand Down Expand Up @@ -866,7 +867,26 @@ - (void)processLogBufferAfterCrash {
if ([[fileURL pathExtension] isEqualToString:kMSLogBufferFileExtension]) {
NSData *serializedLog = [NSData dataWithContentsOfURL:fileURL];
if (serializedLog && serializedLog.length && serializedLog.length > 0) {
id<MSLog> item = [NSKeyedUnarchiver unarchiveObjectWithData:serializedLog];
id<MSLog> item;
NSException *exception;

// Deserialize the log.
@try {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wold-style-cast"
item = (id<MSLog>)[MSUtility unarchiveKeyedData:serializedLog];
#pragma clang diagnostic pop
} @catch (NSException *e) {
exception = e;
}
if (!item || exception) {

// The archived log is not valid.
MSLogError([MSAppCenter logTag], @"Deserialization failed for log: %@",
exception ? exception.reason : @"The log deserialized to NULL.");

continue;
}
if (item) {

// Try to set target token.
Expand Down
4 changes: 2 additions & 2 deletions AppCenterCrashes/AppCenterCrashesTests/MSAppleErrorLogTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ - (void)testSerializationToDictionaryWorks {
- (void)testNSCodingSerializationAndDeserializationWorks {

// When
NSData *serializedEvent = [NSKeyedArchiver archivedDataWithRootObject:self.sut];
id actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedEvent];
NSData *serializedEvent = [MSUtility archiveKeyedData:self.sut];
id actual = [MSUtility unarchiveKeyedData:serializedEvent];

// Then
assertThat(actual, notNilValue());
Expand Down
4 changes: 2 additions & 2 deletions AppCenterCrashes/AppCenterCrashesTests/MSBinaryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ - (void)testNSCodingSerializationAndDeserializationWorks {
MSBinary *sut = [self binary];

// When
NSData *serializedEvent = [NSKeyedArchiver archivedDataWithRootObject:sut];
id actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedEvent];
NSData *serializedEvent = [MSUtility archiveKeyedData:sut];
id actual = [MSUtility unarchiveKeyedData:serializedEvent];

// Then
assertThat(actual, notNilValue());
Expand Down
6 changes: 3 additions & 3 deletions AppCenterCrashes/AppCenterCrashesTests/MSCrashesTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ - (void)testCrashesSetCorrectUserIdToLogs {
[settings stopMocking];
}

#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_MACCATALYST

- (void)testMemoryWarningObserverNotExtension {

Expand Down Expand Up @@ -1241,7 +1241,7 @@ - (void)testMemoryWarningObserverNotExtension {
- (void)testMemoryPressureSourceInExtensionAndMacOS {

// If
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_MACCATALYST
id bundleMock = OCMClassMock([NSBundle class]);
OCMStub([bundleMock mainBundle]).andReturn(bundleMock);
OCMStub([bundleMock executablePath]).andReturn(@"/Application/Executable/Path.appex/42");
Expand All @@ -1260,7 +1260,7 @@ - (void)testMemoryPressureSourceInExtensionAndMacOS {
XCTAssertNil(self.sut.memoryPressureSource);

// Clear
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_MACCATALYST
[bundleMock stopMocking];
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions AppCenterCrashes/AppCenterCrashesTests/MSCrashesUtilTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (void)testCreateCrashesDir {
#if TARGET_OS_TV
expectedDir = @"/Library/Caches/com.microsoft.appcenter/crashes";
#else
#if TARGET_OS_OSX
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
expectedDir = [self getPathWithBundleIdentifier:@"/Library/Application%%20Support/%@/com.microsoft.appcenter/crashes"];
#else
expectedDir = @"/Library/Application%20Support/com.microsoft.appcenter/crashes";
Expand All @@ -64,7 +64,7 @@ - (void)testCreateLogBufferDir {
#if TARGET_OS_TV
expectedDir = @"/Library/Caches/com.microsoft.appcenter/crasheslogbuffer";
#else
#if TARGET_OS_OSX
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
expectedDir = [self getPathWithBundleIdentifier:@"/Library/Application%%20Support/%@/com.microsoft.appcenter/crasheslogbuffer"];
#else
expectedDir = @"/Library/Application%20Support/com.microsoft.appcenter/crasheslogbuffer";
Expand All @@ -89,7 +89,7 @@ - (void)testCreateWrapperExceptionDir {
#if TARGET_OS_TV
expectedDir = @"/Library/Caches/com.microsoft.appcenter/crasheswrapperexceptions";
#else
#if TARGET_OS_OSX
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
expectedDir = [self getPathWithBundleIdentifier:@"/Library/Application%%20Support/%@/com.microsoft.appcenter/crasheswrapperexceptions"];
#else
expectedDir = @"/Library/Application%20Support/com.microsoft.appcenter/crasheswrapperexceptions";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ - (void)testSerializingToDictionary {
- (void)testNSCodingSerializationAndDeserialization {

// When
NSData *serializedEvent = [NSKeyedArchiver archivedDataWithRootObject:self.sut];
MSErrorAttachmentLog *actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedEvent];
NSData *serializedEvent = [MSUtility archiveKeyedData:self.sut];
MSErrorAttachmentLog *actual = [MSUtility unarchiveKeyedData:serializedEvent];

// Then
assertThat(actual, notNilValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ - (void)testNormalize32BitAddress {
}
#endif

#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_MACCATALYST
- (void)testNormalize64BitAddress {

// If
Expand All @@ -571,7 +571,7 @@ - (void)testNormalize64BitAddress {
}
#endif

#if TARGET_OS_OSX
#if TARGET_OS_OSX && !TARGET_OS_MACCATALYST
- (void)testNormalize32BitAddressOnMacOs {

// If
Expand All @@ -586,7 +586,7 @@ - (void)testNormalize32BitAddressOnMacOs {
}
#endif

#if TARGET_OS_OSX
#if TARGET_OS_OSX && !TARGET_OS_MACCATALYST
- (void)testNormalize64BitAddressMacOs {

// If
Expand All @@ -601,7 +601,7 @@ - (void)testNormalize64BitAddressMacOs {
}
#endif

#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_MACCATALYST
- (void)testBinaryImageCountFromReportIsCorrect {

// If
Expand All @@ -618,7 +618,7 @@ - (void)testBinaryImageCountFromReportIsCorrect {
}
#endif

#if TARGET_OS_OSX
#if TARGET_OS_OSX && !TARGET_OS_MACCATALYST
- (void)testCrashReportsParametersFromMacOSReport {
for (unsigned long i = 0; i < kMacOSCrashReportsParameters.count; i++) {

Expand Down
4 changes: 2 additions & 2 deletions AppCenterCrashes/AppCenterCrashesTests/MSExceptionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ - (void)testNSCodingSerializationAndDeserializationWorks {
sut.innerExceptions = @[ [MSCrashesTestUtil exception] ];

// When
NSData *serializedEvent = [NSKeyedArchiver archivedDataWithRootObject:sut];
id actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedEvent];
NSData *serializedEvent = [MSUtility archiveKeyedData:sut];
id actual = [MSUtility unarchiveKeyedData:serializedEvent];

// Then
assertThat(actual, notNilValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ - (void)testSerializationToDictionaryWorks {
- (void)testNSCodingSerializationAndDeserializationWorks {

// When
NSData *serializedEvent = [NSKeyedArchiver archivedDataWithRootObject:self.sut];
id actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedEvent];
NSData *serializedEvent = [MSUtility archiveKeyedData:self.sut];
id actual = [MSUtility unarchiveKeyedData:serializedEvent];

// Then
assertThat(actual, notNilValue());
Expand Down
4 changes: 2 additions & 2 deletions AppCenterCrashes/AppCenterCrashesTests/MSStackFrameTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ - (void)testNSCodingSerializationAndDeserializationWorks {
MSStackFrame *sut = [self stackFrame];

// When
NSData *serializedEvent = [NSKeyedArchiver archivedDataWithRootObject:sut];
id actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedEvent];
NSData *serializedEvent = [MSUtility archiveKeyedData:sut];
id actual = [MSUtility unarchiveKeyedData:serializedEvent];

// Then
assertThat(actual, notNilValue());
Expand Down
4 changes: 2 additions & 2 deletions AppCenterCrashes/AppCenterCrashesTests/MSThreadTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ - (void)testNSCodingSerializationAndDeserializationWorks {
MSThread *sut = [self thread];

// When
NSData *serializedEvent = [NSKeyedArchiver archivedDataWithRootObject:sut];
id actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedEvent];
NSData *serializedEvent = [MSUtility archiveKeyedData:sut];
id actual = [MSUtility unarchiveKeyedData:serializedEvent];

// Then
assertThat(actual, notNilValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ - (void)testSerializationToDictionaryWorks {
- (void)testNSCodingSerializationAndDeserializationWorks {

// When
NSData *serializedWrapperException = [NSKeyedArchiver archivedDataWithRootObject:self.sut];
id actual = [NSKeyedUnarchiver unarchiveObjectWithData:serializedWrapperException];
NSData *serializedWrapperException = [MSUtility archiveKeyedData:self.sut];
id actual = [MSUtility unarchiveKeyedData:serializedWrapperException];

// Then
assertThat(actual, notNilValue());
Expand Down
2 changes: 1 addition & 1 deletion Config/Global.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ CLANG_ANALYZER_GCD_PERFORMANCE = YES

// Enable warnings-are-errors for all modes. Don't do this just yet.
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES
GCC_TREAT_WARNINGS_AS_ERRORS = YES
GCC_TREAT_WARNINGS_AS_ERRORS = NO

// Swift Compiler - Code Generation
SWIFT_ENFORCE_EXCLUSIVE_ACCESS = on
Expand Down