Lift the compact unwind work out into a generic compact unwind parsing API.
This commit is contained in:
Родитель
27f79bbdd7
Коммит
30856528ee
|
@ -415,6 +415,20 @@
|
|||
05F3CD6D16DE7625007911FB /* Tests in Resources */ = {isa = PBXBuildFile; fileRef = 05F3CD6C16DE7625007911FB /* Tests */; };
|
||||
05F3CD6E16DE7625007911FB /* Tests in Resources */ = {isa = PBXBuildFile; fileRef = 05F3CD6C16DE7625007911FB /* Tests */; };
|
||||
05F3CD6F16DE7625007911FB /* Tests in Resources */ = {isa = PBXBuildFile; fileRef = 05F3CD6C16DE7625007911FB /* Tests */; };
|
||||
05F3CD7416DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 05F3CD7216DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h */; };
|
||||
05F3CD7516DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 05F3CD7216DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h */; };
|
||||
05F3CD7616DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 05F3CD7216DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h */; };
|
||||
05F3CD7716DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 05F3CD7216DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h */; };
|
||||
05F3CD7816DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */; };
|
||||
05F3CD7916DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */; };
|
||||
05F3CD7A16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */; };
|
||||
05F3CD7B16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */; };
|
||||
05F3CD7C16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */; };
|
||||
05F3CD7D16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */; };
|
||||
05F3CD7E16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */; };
|
||||
05F3CD8116DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD8016DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m */; };
|
||||
05F3CD8216DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD8016DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m */; };
|
||||
05F3CD8316DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 05F3CD8016DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m */; };
|
||||
05F40ACB0EF7379F008050CF /* PLCrashReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 05F40ACA0EF7379F008050CF /* PLCrashReporter.m */; };
|
||||
05F40ACC0EF7379F008050CF /* PLCrashReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 05F40ACA0EF7379F008050CF /* PLCrashReporter.m */; };
|
||||
05F40ACD0EF7379F008050CF /* PLCrashReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 05F40ACA0EF7379F008050CF /* PLCrashReporter.m */; };
|
||||
|
@ -903,6 +917,9 @@
|
|||
05F3CD6416DD6A58007911FB /* PLCrashFrameCompactUnwind.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLCrashFrameCompactUnwind.h; sourceTree = "<group>"; };
|
||||
05F3CD6816DD6A7A007911FB /* PLCrashFrameCompactUnwindTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLCrashFrameCompactUnwindTests.m; sourceTree = "<group>"; };
|
||||
05F3CD6C16DE7625007911FB /* Tests */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Tests; sourceTree = "<group>"; };
|
||||
05F3CD7216DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PLCrashAsyncCompactUnwindEncoding.h; sourceTree = "<group>"; };
|
||||
05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = PLCrashAsyncCompactUnwindEncoding.c; sourceTree = "<group>"; };
|
||||
05F3CD8016DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLCrashAsyncCompactUnwindEncodingTests.m; sourceTree = "<group>"; };
|
||||
05F40ACA0EF7379F008050CF /* PLCrashReporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLCrashReporter.m; sourceTree = "<group>"; };
|
||||
05F40ADD0EF73A39008050CF /* PLCrashReporterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PLCrashReporterTests.m; sourceTree = "<group>"; };
|
||||
05F40CE70EF7AB80008050CF /* DemoCrash.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoCrash.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
|
@ -1386,6 +1403,7 @@
|
|||
05BB4C9F166D40AD0075171B /* Symbolication */,
|
||||
05BB4C9D166D3BE10075171B /* Mach-O ABI */,
|
||||
05BB4C9E166D409B0075171B /* Obj-C ABI */,
|
||||
05F3CD7116DFC709007911FB /* Compact Unwind Encoding */,
|
||||
);
|
||||
name = "Async-Safe APIs";
|
||||
sourceTree = "<group>";
|
||||
|
@ -1497,6 +1515,16 @@
|
|||
name = "Apple Compact Unwind";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
05F3CD7116DFC709007911FB /* Compact Unwind Encoding */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
05F3CD7216DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h */,
|
||||
05F3CD7316DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c */,
|
||||
05F3CD8016DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m */,
|
||||
);
|
||||
name = "Compact Unwind Encoding";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
05F40CF00EF7ABD6008050CF /* Crash Demo */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -1700,6 +1728,7 @@
|
|||
0573B42E1681098E00395F2A /* PLCrashMachExceptionServer.h in Headers */,
|
||||
FCE4586A7041D332D1025F37 /* PLCrashFrameStackUnwind.h in Headers */,
|
||||
05A17DCF16D7F82700888448 /* PLCrashAsyncThread.h in Headers */,
|
||||
05F3CD7616DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1735,6 +1764,7 @@
|
|||
0573B42F1681098E00395F2A /* PLCrashMachExceptionServer.h in Headers */,
|
||||
FCE45210FDD184E397747BE3 /* PLCrashFrameStackUnwind.h in Headers */,
|
||||
05A17DD016D7F82700888448 /* PLCrashAsyncThread.h in Headers */,
|
||||
05F3CD7716DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1758,6 +1788,7 @@
|
|||
0573B42C1681098E00395F2A /* PLCrashMachExceptionServer.h in Headers */,
|
||||
FCE45B4FD545A258E0292F25 /* PLCrashFrameStackUnwind.h in Headers */,
|
||||
05A17DCD16D7F82700888448 /* PLCrashAsyncThread.h in Headers */,
|
||||
05F3CD7416DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1796,6 +1827,7 @@
|
|||
05A17DEC16DBCDBF00888448 /* PLCrashAsyncThread_x86.h in Headers */,
|
||||
05A17DEE16DBCDBF00888448 /* PLCrashAsyncThread_arm.h in Headers */,
|
||||
05F3CD6516DD6A58007911FB /* PLCrashFrameCompactUnwind.h in Headers */,
|
||||
05F3CD7516DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2312,6 +2344,7 @@
|
|||
05A17DF316DBD0AD00888448 /* PLCrashAsyncThread_x86.c in Sources */,
|
||||
05A17DF816DBD0C200888448 /* PLCrashAsyncThread_arm.c in Sources */,
|
||||
05F3CD6216DD6A3B007911FB /* PLCrashFrameCompactUnwind.c in Sources */,
|
||||
05F3CD7A16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2362,6 +2395,7 @@
|
|||
05A17DF416DBD0AD00888448 /* PLCrashAsyncThread_x86.c in Sources */,
|
||||
05A17DF916DBD0C200888448 /* PLCrashAsyncThread_arm.c in Sources */,
|
||||
05F3CD6316DD6A3B007911FB /* PLCrashFrameCompactUnwind.c in Sources */,
|
||||
05F3CD7B16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2418,6 +2452,8 @@
|
|||
05F3CD5B16DBDB0D007911FB /* PLCrashAsyncThread_arm.c in Sources */,
|
||||
05A17DDE16D80CEC00888448 /* PLCrashTestThreadTests.m in Sources */,
|
||||
05F3CD6916DD6A7A007911FB /* PLCrashFrameCompactUnwindTests.m in Sources */,
|
||||
05F3CD7C16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */,
|
||||
05F3CD8116DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2474,6 +2510,8 @@
|
|||
05A17DD916D80B2A00888448 /* PLCrashTestThread.m in Sources */,
|
||||
05A17DDF16D80CEC00888448 /* PLCrashTestThreadTests.m in Sources */,
|
||||
05F3CD6A16DD6A7A007911FB /* PLCrashFrameCompactUnwindTests.m in Sources */,
|
||||
05F3CD7D16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */,
|
||||
05F3CD8216DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2532,6 +2570,8 @@
|
|||
05F3CD5C16DBF25F007911FB /* PLCrashAsyncThread_x86.c in Sources */,
|
||||
05F3CD5D16DBF262007911FB /* PLCrashAsyncThread_arm.c in Sources */,
|
||||
05F3CD6B16DD6A7A007911FB /* PLCrashFrameCompactUnwindTests.m in Sources */,
|
||||
05F3CD7E16DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */,
|
||||
05F3CD8316DFC78D007911FB /* PLCrashAsyncCompactUnwindEncodingTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2591,6 +2631,7 @@
|
|||
05A17DF116DBD0AD00888448 /* PLCrashAsyncThread_x86.c in Sources */,
|
||||
05A17DF616DBD0C200888448 /* PLCrashAsyncThread_arm.c in Sources */,
|
||||
05F3CD6016DD6A3B007911FB /* PLCrashFrameCompactUnwind.c in Sources */,
|
||||
05F3CD7816DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2650,6 +2691,7 @@
|
|||
05A17DF216DBD0AD00888448 /* PLCrashAsyncThread_x86.c in Sources */,
|
||||
05A17DF716DBD0C200888448 /* PLCrashAsyncThread_arm.c in Sources */,
|
||||
05F3CD6116DD6A3B007911FB /* PLCrashFrameCompactUnwind.c in Sources */,
|
||||
05F3CD7916DFC744007911FB /* PLCrashAsyncCompactUnwindEncoding.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2013 Plausible Labs Cooperative, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import "PLCrashAsyncCompactUnwindEncoding.h"
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2013 Plausible Labs Cooperative, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 2013 Plausible Labs Cooperative, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#import "GTMSenTestCase.h"
|
||||
#import "PLCrashFrameCompactUnwind.h"
|
||||
#import "PLCrashAsyncMachOImage.h"
|
||||
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
#import <mach-o/fat.h>
|
||||
#import <mach-o/arch.h>
|
||||
|
||||
#if TARGET_OS_MAC && (!TARGET_OS_IPHONE)
|
||||
#define TEST_BINARY @"test.macosx"
|
||||
#elif TARGET_OS_SIMULATOR
|
||||
#define TEST_BINARY @"test.sim"
|
||||
#elif TARGET_OS_IPHONE
|
||||
#define TEST_BINARY @"test.ios"
|
||||
#else
|
||||
#error Unsupported target
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* This code tests compact frame unwinding.
|
||||
*/
|
||||
@interface PLCrashAsyncCompactUnwindEncodingTests : SenTestCase {
|
||||
@private
|
||||
/** A mapped Mach-O file */
|
||||
plcrash_async_mobject_t _machoData;
|
||||
|
||||
/** The parsed Mach-O file (this will be a subset of _imageData) */
|
||||
plcrash_async_macho_t _macho;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation PLCrashAsyncCompactUnwindEncodingTests
|
||||
|
||||
/**
|
||||
* Return the full path to the request test resource.
|
||||
*
|
||||
* @param resourceName Relative resource path.
|
||||
*
|
||||
* Test resources are located in Bundle/Resources/Tests/TestClass/ResourceName
|
||||
*/
|
||||
- (NSString *) pathForTestResource: (NSString *) resourceName {
|
||||
NSString *className = NSStringFromClass([self class]);
|
||||
NSString *bundleResources = [[NSBundle bundleForClass: [self class]] resourcePath];
|
||||
NSString *testResources = [bundleResources stringByAppendingPathComponent: @"Tests"];
|
||||
NSString *testRoot = [testResources stringByAppendingPathComponent: className];
|
||||
|
||||
return [testRoot stringByAppendingPathComponent: resourceName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the test resource with the given @a resourceName, and load the resource's data.
|
||||
*
|
||||
* @param resourceName Relative resource path.
|
||||
*/
|
||||
- (NSData *) dataForTestResource: (NSString *) resourceName {
|
||||
NSError *error;
|
||||
NSString *path = [self pathForTestResource: resourceName];
|
||||
NSData *result = [NSData dataWithContentsOfFile: path options: NSDataReadingUncached error: &error];
|
||||
NSAssert(result != nil, @"Failed to load resource data: %@", error);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the Mach-O FAT binary mapped by @a mobj for a fat architecture that best matches the host architecture,
|
||||
* and then return the architecture's image @a size and @a offset from the head of @a mobj;
|
||||
*/
|
||||
- (void) findBinary: (plcrash_async_mobject_t *) mobj offset: (uint32_t *) offset size: (uint32_t *) size {
|
||||
struct fat_header *fh = plcrash_async_mobject_remap_address(mobj, mobj->task_address, sizeof(struct fat_header));
|
||||
STAssertNotNULL(fh, @"Could not load fat header");
|
||||
|
||||
if (fh->magic != FAT_MAGIC && fh->magic != FAT_CIGAM)
|
||||
STFail(@"Not a fat binary!");
|
||||
|
||||
/* Load all the fat architectures */
|
||||
pl_vm_address_t base = mobj->task_address + sizeof(*fh);
|
||||
uint32_t count = OSSwapBigToHostInt32(fh->nfat_arch);
|
||||
struct fat_arch *archs = calloc(count, sizeof(*archs));
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
struct fat_arch *fa = plcrash_async_mobject_remap_address(mobj, base+(i*sizeof(*fa)), sizeof(*fa));
|
||||
archs[i].cputype = OSSwapBigToHostInt32(fa->cputype);
|
||||
archs[i].cpusubtype = OSSwapBigToHostInt32(fa->cpusubtype);
|
||||
archs[i].offset = OSSwapBigToHostInt32(fa->offset);
|
||||
archs[i].size = OSSwapBigToHostInt32(fa->size);
|
||||
archs[i].align = OSSwapBigToHostInt32(fa->align);
|
||||
}
|
||||
|
||||
/* Find the right architecture */
|
||||
const NXArchInfo *local_arch = NXGetLocalArchInfo();
|
||||
const struct fat_arch *best_arch = NXFindBestFatArch(local_arch->cputype, local_arch->cpusubtype, archs, count);
|
||||
STAssertNotNULL(best_arch, @"Could not find a matching entry for the host architecture");
|
||||
|
||||
/* Clean up */
|
||||
free(archs);
|
||||
|
||||
/* Done! */
|
||||
*offset = best_arch->offset;
|
||||
*size = best_arch->size;
|
||||
}
|
||||
|
||||
- (void) setUp {
|
||||
uint32_t offset, length;
|
||||
|
||||
/* Load the image into a memory object */
|
||||
NSData *mappedImage = [self dataForTestResource: TEST_BINARY];
|
||||
plcrash_async_mobject_init(&_machoData, mach_task_self(), (pl_vm_address_t) [mappedImage bytes], [mappedImage length]);
|
||||
/* Find a binary that matches the host */
|
||||
[self findBinary: &_machoData offset: &offset size: &length];
|
||||
void *macho_ptr = plcrash_async_mobject_remap_address(&_machoData, _machoData.task_address + offset, length);
|
||||
STAssertNotNULL(macho_ptr, @"Discovered binary is not within the mapped memory range");
|
||||
|
||||
/* Parse the image */
|
||||
plcrash_error_t err;
|
||||
|
||||
err = plcrash_nasync_macho_init(&_macho, mach_task_self(), [TEST_BINARY UTF8String], macho_ptr);
|
||||
STAssertEquals(err, PLCRASH_ESUCCESS, @"Failed to initialize Mach-O parser");
|
||||
}
|
||||
|
||||
- (void) tearDown {
|
||||
plcrash_nasync_macho_free(&_macho);
|
||||
plcrash_async_mobject_free(&_machoData);
|
||||
}
|
||||
|
||||
- (void) testSomething {
|
||||
|
||||
}
|
||||
|
||||
@end
|
|
@ -27,22 +27,6 @@
|
|||
|
||||
#import "GTMSenTestCase.h"
|
||||
#import "PLCrashFrameCompactUnwind.h"
|
||||
#import "PLCrashAsyncMachOImage.h"
|
||||
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
#import <mach-o/fat.h>
|
||||
#import <mach-o/arch.h>
|
||||
|
||||
#if TARGET_OS_MAC && (!TARGET_OS_IPHONE)
|
||||
#define TEST_BINARY @"test.macosx"
|
||||
#elif TARGET_OS_SIMULATOR
|
||||
#define TEST_BINARY @"test.sim"
|
||||
#elif TARGET_OS_IPHONE
|
||||
#define TEST_BINARY @"test.ios"
|
||||
#else
|
||||
#error Unsupported target
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -51,108 +35,9 @@
|
|||
*/
|
||||
@interface PLCrashFrameCompactUnwindTests : SenTestCase {
|
||||
@private
|
||||
/** A mapped Mach-O file */
|
||||
plcrash_async_mobject_t _machoData;
|
||||
|
||||
/** The parsed Mach-O file (this will be a subset of _imageData) */
|
||||
plcrash_async_macho_t _macho;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation PLCrashFrameCompactUnwindTests
|
||||
|
||||
/**
|
||||
* Return the full path to the request test resource.
|
||||
*
|
||||
* @param resourceName Relative resource path.
|
||||
*
|
||||
* Test resources are located in Bundle/Resources/Tests/TestClass/ResourceName
|
||||
*/
|
||||
- (NSString *) pathForTestResource: (NSString *) resourceName {
|
||||
NSString *className = NSStringFromClass([self class]);
|
||||
NSString *bundleResources = [[NSBundle bundleForClass: [self class]] resourcePath];
|
||||
NSString *testResources = [bundleResources stringByAppendingPathComponent: @"Tests"];
|
||||
NSString *testRoot = [testResources stringByAppendingPathComponent: className];
|
||||
|
||||
return [testRoot stringByAppendingPathComponent: resourceName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the test resource with the given @a resourceName, and load the resource's data.
|
||||
*
|
||||
* @param resourceName Relative resource path.
|
||||
*/
|
||||
- (NSData *) dataForTestResource: (NSString *) resourceName {
|
||||
NSError *error;
|
||||
NSString *path = [self pathForTestResource: resourceName];
|
||||
NSData *result = [NSData dataWithContentsOfFile: path options: NSDataReadingUncached error: &error];
|
||||
NSAssert(result != nil, @"Failed to load resource data: %@", error);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the Mach-O FAT binary mapped by @a mobj for a fat architecture that best matches the host architecture,
|
||||
* and then return the architecture's image @a size and @a offset from the head of @a mobj;
|
||||
*/
|
||||
- (void) findBinary: (plcrash_async_mobject_t *) mobj offset: (uint32_t *) offset size: (uint32_t *) size {
|
||||
struct fat_header *fh = plcrash_async_mobject_remap_address(mobj, mobj->task_address, sizeof(struct fat_header));
|
||||
STAssertNotNULL(fh, @"Could not load fat header");
|
||||
|
||||
if (fh->magic != FAT_MAGIC && fh->magic != FAT_CIGAM)
|
||||
STFail(@"Not a fat binary!");
|
||||
|
||||
/* Load all the fat architectures */
|
||||
pl_vm_address_t base = mobj->task_address + sizeof(*fh);
|
||||
uint32_t count = OSSwapBigToHostInt32(fh->nfat_arch);
|
||||
struct fat_arch *archs = calloc(count, sizeof(*archs));
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
struct fat_arch *fa = plcrash_async_mobject_remap_address(mobj, base+(i*sizeof(*fa)), sizeof(*fa));
|
||||
archs[i].cputype = OSSwapBigToHostInt32(fa->cputype);
|
||||
archs[i].cpusubtype = OSSwapBigToHostInt32(fa->cpusubtype);
|
||||
archs[i].offset = OSSwapBigToHostInt32(fa->offset);
|
||||
archs[i].size = OSSwapBigToHostInt32(fa->size);
|
||||
archs[i].align = OSSwapBigToHostInt32(fa->align);
|
||||
}
|
||||
|
||||
/* Find the right architecture */
|
||||
const NXArchInfo *local_arch = NXGetLocalArchInfo();
|
||||
const struct fat_arch *best_arch = NXFindBestFatArch(local_arch->cputype, local_arch->cpusubtype, archs, count);
|
||||
STAssertNotNULL(best_arch, @"Could not find a matching entry for the host architecture");
|
||||
|
||||
/* Clean up */
|
||||
free(archs);
|
||||
|
||||
/* Done! */
|
||||
*offset = best_arch->offset;
|
||||
*size = best_arch->size;
|
||||
}
|
||||
|
||||
- (void) setUp {
|
||||
uint32_t offset, length;
|
||||
|
||||
/* Load the image into a memory object */
|
||||
NSData *mappedImage = [self dataForTestResource: TEST_BINARY];
|
||||
plcrash_async_mobject_init(&_machoData, mach_task_self(), (pl_vm_address_t) [mappedImage bytes], [mappedImage length]);
|
||||
/* Find a binary that matches the host */
|
||||
[self findBinary: &_machoData offset: &offset size: &length];
|
||||
void *macho_ptr = plcrash_async_mobject_remap_address(&_machoData, _machoData.task_address + offset, length);
|
||||
STAssertNotNULL(macho_ptr, @"Discovered binary is not within the mapped memory range");
|
||||
|
||||
/* Parse the image */
|
||||
plcrash_error_t err;
|
||||
|
||||
err = plcrash_nasync_macho_init(&_macho, mach_task_self(), [TEST_BINARY UTF8String], macho_ptr);
|
||||
STAssertEquals(err, PLCRASH_ESUCCESS, @"Failed to initialize Mach-O parser");
|
||||
}
|
||||
|
||||
- (void) tearDown {
|
||||
plcrash_nasync_macho_free(&_macho);
|
||||
plcrash_async_mobject_free(&_machoData);
|
||||
}
|
||||
|
||||
- (void) testSomething {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Загрузка…
Ссылка в новой задаче