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 = @"???";
/* Determine the architecture string */
NSString *archName = @"???";
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;
}
}
NSString *archName = [self archNameFromImageInfo:imageInfo];
/* Determine if this is the main executable or an app specific framework*/
NSString *binaryDesignator = @" ";
@ -472,59 +420,7 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
uuid = @"???";
/* Determine the architecture string */
NSString *archName = @"???";
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;
}
}
NSString *archName = [self archNameFromImageInfo:imageInfo];
/* Determine if this is the app executable or app specific framework */
NSString *imagePath = [imageInfo.imageName stringByStandardizingPath];
@ -546,6 +442,66 @@ NSInteger binaryImageSort(id binary1, id binary2, void *context);
return appUUIDs;
}
+ (NSString *)archNameFromImageInfo:(BITPLCrashReportBinaryImageInfo *)imageInfo
{
NSString *archName = @"???";
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";
break;
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;
}
}
return archName;
}
@end