-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Crashlytics add new Record Exception Model API #5055
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,16 @@ | |
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#import "FIRCLSFileManager.h" | ||
#import "FIRCLSInstallIdentifierModel.h" | ||
#import "FIRCLSInternalReport.h" | ||
#import "FIRCLSSettings.h" | ||
|
||
#include "FIRCLSApplication.h" | ||
#include "FIRCLSCrashedMarkerFile.h" | ||
#include "FIRCLSDefines.h" | ||
#include "FIRCLSFeatures.h" | ||
#include "FIRCLSGlobals.h" | ||
#include "FIRCLSInternalReport.h" | ||
#include "FIRCLSProcess.h" | ||
#include "FIRCLSUtility.h" | ||
|
||
|
@@ -45,7 +49,61 @@ | |
static const char* FIRCLSContextAppendToRoot(NSString* root, NSString* component); | ||
static void FIRCLSContextAllocate(FIRCLSContext* context); | ||
|
||
bool FIRCLSContextInitialize(const FIRCLSContextInitData* initData) { | ||
FIRCLSContextInitData FIRCLSContextBuildInitData(FIRCLSInternalReport* report, | ||
FIRCLSSettings* settings, | ||
FIRCLSInstallIdentifierModel* installIDModel, | ||
FIRCLSFileManager* fileManager) { | ||
// Because we need to start the crash reporter right away, | ||
// it starts up either with default settings, or cached settings | ||
// from the last time they were fetched | ||
|
||
FIRCLSContextInitData initData; | ||
|
||
memset(&initData, 0, sizeof(FIRCLSContextInitData)); | ||
|
||
initData.customBundleId = nil; | ||
initData.installId = [installIDModel.installID UTF8String]; | ||
initData.sessionId = [[report identifier] UTF8String]; | ||
initData.rootPath = [[report path] UTF8String]; | ||
initData.previouslyCrashedFileRootPath = [[fileManager rootPath] UTF8String]; | ||
initData.errorsEnabled = [settings errorReportingEnabled]; | ||
initData.customExceptionsEnabled = [settings customExceptionsEnabled]; | ||
initData.maxCustomExceptions = [settings maxCustomExceptions]; | ||
initData.maxErrorLogSize = [settings errorLogBufferSize]; | ||
initData.maxLogSize = [settings logBufferSize]; | ||
initData.maxKeyValues = [settings maxCustomKeys]; | ||
|
||
// If this is set, then we could attempt to do a synchronous submission for certain kinds of | ||
// events (exceptions). This is a very cool feature, but adds complexity to the backend. For now, | ||
// we're going to leave this disabled. It does work in the exception case, but will ultimtely | ||
// result in the following crash to be discared. Usually that crash isn't interesting. But, if it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest replacing with: "If initData.delegate is set, we can attempt a synchronous submission for certain kinds of events (exceptions). This is a useful feature but adds complexity to the backend. For now, this is disabled. It works in the exception case but ultimately results in discarding the following crash. Usually the crash doesn't provide interesting data, but if it does, you may want to see it before its discarded." This avoids using "we" and "cool". Makes it clear what crash is going to be discarded. Removes past tense. Makes it clear what "we'd never have a chance to see it" means. Makes it clear what method we're talking about ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean "discarded" instead of "discared"? |
||
// was, we'd never have a chance to see it. | ||
initData.delegate = nil; | ||
|
||
#if CLS_MACH_EXCEPTION_SUPPORTED | ||
__block exception_mask_t mask = 0; | ||
|
||
// TODO(b/141241224) This if statement was hardcoded to no, so this block was never run | ||
// FIRCLSSignalEnumerateHandledSignals(^(int idx, int signal) { | ||
// if ([self.delegate ensureDeliveryOfUnixSignal:signal]) { | ||
// mask |= FIRCLSMachExceptionMaskForSignal(signal); | ||
// } | ||
// }); | ||
|
||
initData.machExceptionMask = mask; | ||
#endif | ||
|
||
return initData; | ||
} | ||
|
||
bool FIRCLSContextInitialize(FIRCLSInternalReport* report, | ||
FIRCLSSettings* settings, | ||
FIRCLSInstallIdentifierModel* installIDModel, | ||
FIRCLSFileManager* fileManager) { | ||
FIRCLSContextInitData initDataObj = | ||
FIRCLSContextBuildInitData(report, settings, installIDModel, fileManager); | ||
FIRCLSContextInitData* initData = &initDataObj; | ||
|
||
if (!initData) { | ||
return false; | ||
} | ||
|
@@ -197,7 +255,14 @@ bool FIRCLSContextInitialize(const FIRCLSContextInitData* initData) { | |
return true; | ||
} | ||
|
||
void FIRCLSContextUpdateMetadata(const FIRCLSContextInitData* initData) { | ||
void FIRCLSContextUpdateMetadata(FIRCLSInternalReport* report, | ||
FIRCLSSettings* settings, | ||
FIRCLSInstallIdentifierModel* installIDModel, | ||
FIRCLSFileManager* fileManager) { | ||
FIRCLSContextInitData initDataObj = | ||
FIRCLSContextBuildInitData(report, settings, installIDModel, fileManager); | ||
FIRCLSContextInitData* initData = &initDataObj; | ||
|
||
NSString* rootPath = [NSString stringWithUTF8String:initData->rootPath]; | ||
|
||
const char* metaDataPath = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2020 Google | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "FIRExceptionModel.h" | ||
|
||
@interface FIRExceptionModel () | ||
|
||
@property(nonatomic, copy) NSString *name; | ||
@property(nonatomic, copy) NSString *reason; | ||
|
||
@end | ||
|
||
@implementation FIRExceptionModel | ||
|
||
- (instancetype)initWithName:(NSString *)name reason:(NSString *)reason { | ||
self = [super init]; | ||
if (!self) { | ||
return nil; | ||
} | ||
|
||
_name = [name copy]; | ||
_reason = [reason copy]; | ||
|
||
return self; | ||
} | ||
|
||
+ (instancetype)exceptionModelWithName:(NSString *)name reason:(NSString *)reason { | ||
return [[FIRExceptionModel alloc] initWithName:name reason:reason]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2020 Google | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "FIRStackFrame_Private.h" | ||
|
||
@interface FIRStackFrame () | ||
|
||
@property(nonatomic, copy, nullable) NSString *symbol; | ||
jasonhu-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@property(nonatomic, copy, nullable) NSString *rawSymbol; | ||
@property(nonatomic, copy, nullable) NSString *library; | ||
@property(nonatomic, copy, nullable) NSString *fileName; | ||
@property(nonatomic, assign) uint32_t lineNumber; | ||
@property(nonatomic, assign) uint64_t offset; | ||
jasonhu-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@property(nonatomic, assign) uint64_t address; | ||
|
||
@property(nonatomic, assign) BOOL isSymbolicated; | ||
|
||
@end | ||
|
||
@implementation FIRStackFrame | ||
|
||
#pragma mark - Public Methods | ||
|
||
- (instancetype)initWithSymbol:(NSString *)symbol file:(NSString *)file line:(NSInteger)line { | ||
self = [super init]; | ||
if (!self) { | ||
return nil; | ||
} | ||
|
||
_symbol = [symbol copy]; | ||
_fileName = [file copy]; | ||
_lineNumber = (uint32_t)line; | ||
|
||
_isSymbolicated = true; | ||
|
||
return self; | ||
} | ||
|
||
+ (instancetype)stackFrameWithSymbol:(NSString *)symbol file:(NSString *)file line:(NSInteger)line { | ||
return [[FIRStackFrame alloc] initWithSymbol:symbol file:file line:line]; | ||
} | ||
|
||
#pragma mark - Internal Methods | ||
|
||
+ (instancetype)stackFrame { | ||
return [[self alloc] init]; | ||
} | ||
|
||
+ (instancetype)stackFrameWithAddress:(NSUInteger)address { | ||
FIRStackFrame *frame = [self stackFrame]; | ||
|
||
[frame setAddress:address]; | ||
|
||
return frame; | ||
} | ||
|
||
+ (instancetype)stackFrameWithSymbol:(NSString *)symbol { | ||
FIRStackFrame *frame = [self stackFrame]; | ||
|
||
frame.symbol = symbol; | ||
frame.rawSymbol = symbol; | ||
|
||
return frame; | ||
} | ||
|
||
#pragma mark - Overrides | ||
|
||
- (NSString *)description { | ||
if (self.isSymbolicated) { | ||
return [NSString | ||
stringWithFormat:@"{%@ - %@:%u}", [self fileName], [self symbol], [self lineNumber]]; | ||
} | ||
|
||
if (self.fileName) { | ||
return [NSString stringWithFormat:@"{[0x%llx] %@ - %@:%u}", [self address], [self fileName], | ||
[self symbol], [self lineNumber]]; | ||
} | ||
|
||
return [NSString | ||
stringWithFormat:@"{[0x%llx + %u] %@}", [self address], [self lineNumber], [self symbol]]; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest replacing with: "Because we need to start the crash reporter right away, it starts up with either default settings or cached settings from the last time the crashes were fetched."