I need to debug heap overflows in a very large project. After playing with valgrind a bit, it seems like the perfect tool for detecting heap block overruns in C, so I'd like to run our iOS app with it.
I've built and installed valgrind from trunk on OS X Yosemite and have written a test program with intentional heap overflows and verified that valgrind catches and reports them.
Now I want to run a test app in the simulator with it. I've read that it can be run in the iOS simulator by using execl(), but when I do so, I see the following error in the console.
dyld: missing LC_DYLD_INFO load command
After that, the app will crash in dyldbootstrap::rebaseDyld() with EXC_BAD_ACCESS. Is something else necessary here? Valgrind apparently also supports arm64 now as well. Is it possible to package the valgrind executable with my app and run it on a device?
#define VALGRIND "/usr/local/bin/valgrind"
int main(int argc, char * argv[]) {
if ( argc >= 2 && strcmp(argv[1], "-valgrind") == 0 ) {
if ( execl(VALGRIND, VALGRIND, argv[0], NULL) < 0 ) {
NSLog(@"Failed to relaunch under valgrind");
exit(1);
}
NSLog(@"Running under valgrind!!");
}
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}