I need to debug heap overflow in a very large project. After playing with valgrind a bit, it seems like the perfect tool to detect heap block overflows in C, so I would like to run an iOS application with it.
I built and installed valgrind from trunk on OS X Yosemite and wrote a test program with deliberate heap overflow and checked that valgrind catches and reports this.
Now I want to run a test application in a simulator. I read that it can be run in the iOS simulator using execl (), but when I do this, I see the following error in the console.
dyld: missing load command LC_DYLD_INFO
After that, the application crashes in dyldbootstrap :: rebaseDyld () with EXC_BAD_ACCESS. Is something else needed here? Valgrind apparently also supports arm64 now. Is it possible to pack the valgrind executable file with my application and run it on the 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])); } }
source share