Pulled architecture detection out into a separate method to eliminate duplicate code.

Added break for CPU_SUBTYPE_ARM_V8 to avoid falling through to the default case.
This commit is contained in:
Kent Sutherland 2013-09-13 15:20:22 -04:00
parent 955fe9c2eb
commit aeb64a7da4

View File

@ -360,59 +360,7 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
uuid = @"???"; uuid = @"???";
/* Determine the architecture string */ /* Determine the architecture string */
NSString *archName = @"???"; NSString *archName = [self archNameFromImageInfo:imageInfo];
if (imageInfo.codeType != nil && imageInfo.codeType.typeEncoding == PLCrashReportProcessorTypeEncodingMach) {
switch (imageInfo.codeType.type) {
case CPU_TYPE_ARM:
/* Apple includes subtype for ARM binaries. */
switch (imageInfo.codeType.subtype) {
case CPU_SUBTYPE_ARM_V6:
archName = @"armv6";
break;
case CPU_SUBTYPE_ARM_V7:
archName = @"armv7";
break;
case CPU_SUBTYPE_ARM_V7S:
archName = @"armv7s";
break;
default:
archName = @"arm-unknown";
break;
}
break;
case CPU_TYPE_ARM64:
/* Apple includes subtype for ARM64 binaries. */
switch (imageInfo.codeType.subtype) {
case CPU_SUBTYPE_ARM_V8:
archName = @"arm64";
default:
archName = @"arm64-unknown";
break;
}
break;
case CPU_TYPE_X86:
archName = @"i386";
break;
case CPU_TYPE_X86_64:
archName = @"x86_64";
break;
case CPU_TYPE_POWERPC:
archName = @"powerpc";
break;
default:
// Use the default archName value (initialized above).
break;
}
}
/* Determine if this is the main executable or an app specific framework*/ /* Determine if this is the main executable or an app specific framework*/
NSString *binaryDesignator = @" "; NSString *binaryDesignator = @" ";
@ -472,6 +420,30 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
uuid = @"???"; uuid = @"???";
/* Determine the architecture string */ /* Determine the architecture string */
NSString *archName = [self archNameFromImageInfo:imageInfo];
/* Determine if this is the app executable or app specific framework */
NSString *imagePath = [imageInfo.imageName stringByStandardizingPath];
NSString *appBundleContentsPath = [[report.processInfo.processPath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
NSString *imageType = @"";
if ([imageInfo.imageName isEqual: report.processInfo.processPath]) {
imageType = @"app";
} else {
imageType = @"framework";
}
if ([imagePath isEqual: report.processInfo.processPath] || [imagePath hasPrefix:appBundleContentsPath]) {
[appUUIDs addObject:@{kBITBinaryImageKeyUUID: uuid, kBITBinaryImageKeyArch: archName, kBITBinaryImageKeyType: imageType}];
}
}
return appUUIDs;
}
+ (NSString *)archNameFromImageInfo:(BITPLCrashReportBinaryImageInfo *)imageInfo
{
NSString *archName = @"???"; NSString *archName = @"???";
if (imageInfo.codeType != nil && imageInfo.codeType.typeEncoding == PLCrashReportProcessorTypeEncodingMach) { if (imageInfo.codeType != nil && imageInfo.codeType.typeEncoding == PLCrashReportProcessorTypeEncodingMach) {
switch (imageInfo.codeType.type) { switch (imageInfo.codeType.type) {
@ -501,6 +473,7 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
switch (imageInfo.codeType.subtype) { switch (imageInfo.codeType.subtype) {
case CPU_SUBTYPE_ARM_V8: case CPU_SUBTYPE_ARM_V8:
archName = @"arm64"; archName = @"arm64";
break;
default: default:
archName = @"arm64-unknown"; archName = @"arm64-unknown";
@ -526,24 +499,7 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
} }
} }
/* Determine if this is the app executable or app specific framework */ return archName;
NSString *imagePath = [imageInfo.imageName stringByStandardizingPath];
NSString *appBundleContentsPath = [[report.processInfo.processPath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
NSString *imageType = @"";
if ([imageInfo.imageName isEqual: report.processInfo.processPath]) {
imageType = @"app";
} else {
imageType = @"framework";
}
if ([imagePath isEqual: report.processInfo.processPath] || [imagePath hasPrefix:appBundleContentsPath]) {
[appUUIDs addObject:@{kBITBinaryImageKeyUUID: uuid, kBITBinaryImageKeyArch: archName, kBITBinaryImageKeyType: imageType}];
}
}
return appUUIDs;
} }
@end @end