Encode the incident identifier directly as a UUID value.

This commit is contained in:
Landon Fuller 2013-07-11 17:07:21 -04:00
Родитель db087b6832
Коммит 418cef4d2a
8 изменённых файлов: 75 добавлений и 30 удалений

Просмотреть файл

@ -319,8 +319,9 @@ message CrashReport {
/** If true, this report was generated on request, and no crash occured. */
required bool user_requested = 1;
/** UUID unique for this crash */
optional string incident_id = 2;
/** A client-generated 16 byte OSF standard UUID for this report. May be used to filter duplicate reports submitted
* by a single client. */
optional bytes uuid = 2;
}
/* Report format information. Required for all v1.1+ crash reports. */

Просмотреть файл

@ -32,6 +32,8 @@
#import "PLCrashAsync.h"
#import "PLCrashAsyncImageList.h"
#include <uuid/uuid.h>
/**
* @internal
* @defgroup plcrash_log_writer Crash Log Writer
@ -55,8 +57,8 @@ typedef struct plcrash_log_writer {
* report */
bool user_requested;
/** Incident Identifier */
char *incident_id;
/** Report UUID */
uuid_t uuid_bytes;
} report_info;
/** System data */

Просмотреть файл

@ -234,8 +234,8 @@ enum {
/** CrashReport.report_info.crashed */
PLCRASH_PROTO_REPORT_INFO_USER_REQUESTED_ID = 1,
/** CrashReport.report_info.incident */
PLCRASH_PROTO_REPORT_INFO_INCIDENT_ID = 2,
/** CrashReport.report_info.uuid */
PLCRASH_PROTO_REPORT_INFO_UUID_ID = 2,
};
/**
@ -264,8 +264,15 @@ plcrash_error_t plcrash_log_writer_init (plcrash_log_writer_t *writer,
/* Default to false */
writer->report_info.user_requested = user_requested;
/* Generate a UUID for this incident */
writer->report_info.incident_id = strdup([[[NSUUID UUID] UUIDString] UTF8String]);
/* Generate a UUID for this incident; CFUUID is used in favor of NSUUID as to maintain compatibility
* with (Mac OS X 10.7|iOS 5) and earlier. */
{
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuid);
PLCF_ASSERT(sizeof(bytes) == sizeof(writer->report_info.uuid_bytes));
memcpy(writer->report_info.uuid_bytes, &bytes, sizeof(writer->report_info.uuid_bytes));
CFRelease(uuid);
}
/* Fetch the application information */
{
@ -1094,8 +1101,12 @@ static size_t plcrash_writer_write_report_info (plcrash_async_file_t *file, plcr
/* Note crashed status */
rv += plcrash_writer_pack(file, PLCRASH_PROTO_REPORT_INFO_USER_REQUESTED_ID, PLPROTOBUF_C_TYPE_BOOL, &writer->report_info.user_requested);
/* Incident Identifier */
rv += plcrash_writer_pack(file, PLCRASH_PROTO_REPORT_INFO_INCIDENT_ID, PLPROTOBUF_C_TYPE_STRING, writer->report_info.incident_id);
/* Write the 128-bit UUID */
PLProtobufCBinaryData uuid_bin;
uuid_bin.len = sizeof(writer->report_info.uuid_bytes);
uuid_bin.data = &writer->report_info.uuid_bytes;
rv += plcrash_writer_pack(file, PLCRASH_PROTO_REPORT_INFO_UUID_ID, PLPROTOBUF_C_TYPE_BYTES, &uuid_bin);
return rv;
}

Просмотреть файл

@ -334,6 +334,16 @@
return;
STAssertFalse(crashReport->report_info->user_requested, @"Report not correctly marked as non-user-requested");
STAssertTrue(crashReport->report_info->has_uuid, @"Report missing a UUID value");
STAssertEquals((size_t)16, crashReport->report_info->uuid.len, @"UUID is not expected 16 bytes");
{
CFUUIDBytes uuid_bytes;
memcpy(&uuid_bytes, crashReport->report_info->uuid.data, sizeof(uuid_bytes));
CFUUIDRef uuid = CFUUIDCreateFromUUIDBytes(NULL, uuid_bytes);
STAssertNotNULL(uuid, @"Value not parsable as a UUID");
if (uuid != NULL)
CFRelease(uuid);
}
/* Test the report */
[self checkSystemInfo: crashReport];

Просмотреть файл

@ -41,6 +41,12 @@
#import "PLCrashReportSystemInfo.h"
#import "PLCrashReportThreadInfo.h"
#import <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 || __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
#define PLCRASH_PRIVATE_HAS_NSUUID 1
#endif
/**
* @ingroup constants
* Crash file magic identifier */
@ -112,7 +118,7 @@ typedef struct _PLCrashReportDecoder _PLCrashReportDecoder;
BOOL _userRequested;
/** Report UUID */
NSString *_incidentIdentifier;
CFUUIDRef _uuid;
}
- (id) initWithData: (NSData *) encodedData error: (NSError **) outError;
@ -183,8 +189,10 @@ typedef struct _PLCrashReportDecoder _PLCrashReportDecoder;
@property(nonatomic, readonly) BOOL userRequested;
/**
* Incident Identifier. A UUID unique to this crash report.
* A client-generated 16-byte UUID. May be used to filter duplicate reports submitted or generated
* by a single client. Only available in later (v1.2+) crash report format versions. If not available,
* will be NULL.
*/
@property(nonatomic, readonly) NSString *incidentIdentifier;
@property(nonatomic, readonly) CFUUIDRef uuidRef;
@end

Просмотреть файл

@ -94,19 +94,24 @@ static void populate_nserror (NSError **error, PLCrashReporterError code, NSStri
/* Report info (optional) */
_userRequested = NO;
_incidentIdentifier = nil;
if (_decoder->crashReport->report_info) {
_uuid = NULL;
if (_decoder->crashReport->report_info != NULL) {
_userRequested = _decoder->crashReport->report_info->user_requested;
/* Incident Identifier (optional) */
if (_decoder->crashReport->report_info->incident_id) {
_incidentIdentifier = [[NSString stringWithUTF8String:_decoder->crashReport->report_info->incident_id] retain];
}
}
/* Report UUID (optional)
* If our minimum supported target is bumped to (10.8+, iOS 6.0+), NSUUID should
* be used instead. */
if (_decoder->crashReport->report_info->has_uuid) {
/* Validate the UUID length */
if (_decoder->crashReport->report_info->uuid.len != sizeof(uuid_t)) {
populate_nserror(outError, PLCrashReporterErrorCrashReportInvalid , @"Report UUID value is not a standard 16 bytes");
goto error;
}
/* If no incident identifier from client, generate one now */
if (_incidentIdentifier == nil) {
_incidentIdentifier = [[[NSUUID UUID] UUIDString] retain];
CFUUIDBytes uuid_bytes;
memcpy(&uuid_bytes, _decoder->crashReport->report_info->uuid.data, _decoder->crashReport->report_info->uuid.len);
_uuid = CFUUIDCreateFromUUIDBytes(NULL, uuid_bytes);
}
}
/* System info */
@ -172,7 +177,9 @@ error:
[_threads release];
[_images release];
[_exceptionInfo release];
[_incidentIdentifier release];
if (_uuid != NULL)
CFRelease(_uuid);
/* Free the decoder state */
if (_decoder != NULL) {
@ -233,7 +240,7 @@ error:
@synthesize images = _images;
@synthesize exceptionInfo = _exceptionInfo;
@synthesize userRequested = _userRequested;
@synthesize incidentIdentifier = _incidentIdentifier;
@synthesize uuidRef = _uuid;
@end

Просмотреть файл

@ -123,9 +123,8 @@
/* Report info */
STAssertFalse(crashLog.userRequested, @"Crash should not be user requested");
STAssertNotNil(crashLog.incidentIdentifier, @"No incident identifier");
STAssertNotNil([[NSUUID new] initWithUUIDString:crashLog.incidentIdentifier], @"incident identifier not a UUID");
STAssertNotNULL(crashLog.uuidRef, @"No report UUID");
/* System info */
STAssertNotNil(crashLog.systemInfo, @"No system information available");
STAssertNotNil(crashLog.systemInfo.operatingSystemVersion, @"OS version is nil");

Просмотреть файл

@ -46,6 +46,7 @@
@interface PLCrashReportTextFormatter (PrivateAPI)
NSInteger binaryImageSort(id binary1, id binary2, void *context);
+ (NSString *) formatStackFrame: (PLCrashReportStackFrameInfo *) frameInfo
frameIndex: (NSUInteger) frameIndex
report: (PLCrashReport *) report
@ -58,7 +59,6 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
*/
@implementation PLCrashReportTextFormatter
/**
* Formats the provided @a report as human-readable text in the given @a textFormat, and return
* the formatted result as a string.
@ -168,7 +168,13 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
if (report.hasMachineInfo && report.machineInfo.modelName != nil)
hardwareModel = report.machineInfo.modelName;
[text appendFormat: @"Incident Identifier: %@\n", report.incidentIdentifier];
NSString *incidentIdentifier = @"???";
if (report.uuidRef != NULL) {
incidentIdentifier = (NSString *) CFUUIDCreateString(NULL, report.uuidRef);
[incidentIdentifier autorelease];
}
[text appendFormat: @"Incident Identifier: %@\n", incidentIdentifier];
[text appendFormat: @"CrashReporter Key: TODO\n"];
[text appendFormat: @"Hardware Model: %@\n", hardwareModel];
}
@ -506,6 +512,7 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
symbolString];
}
/**
* Sort PLCrashReportBinaryImageInfo instances by their starting address.
*/